asp.net mvc 2 - When i select CheckBox().I need to update its value into DB - MVC2,AJAx,JQuery -


please find code tried update db using mvc2.but unable update

view page ajax code

<script src="../../scripts/jquery-1.4.1.js" type="text/javascript"></script> <script src="../../scripts/microsoftajax.js" type="text/javascript"></script> <script language="javascript" type="text/javascript">    $('#cbid').click(function(){     $.ajax({ url: 'home/about',     type: 'post',     data: { checkbox: $('#cbid').attr('checked') },     success: function(o) { alert('saved'); }                       }); </script> <div class="bgdiv"> <input id="cbid" type="checkbox" name="selectedobject" value="cbvalue" /> 

controller page code

 public actionresult about(string str)         {             aboutmodels objam = new aboutmodels();//model class name             polloptions = objam.dbvalue(str);//call model function udate table             return view();         } 

please advice

you should either declare event handler in ready function or declare live or delegate methods like

<script language="javascript" type="text/javascript"> $(function(){      $('#cbid').click(function(){     $.ajax({ url: 'home/about',     type: 'post',     data: { checkbox: $('#cbid').attr('checked') },     success: function(o) { alert('saved'); }                       });       });  }); </script> 

the problem script running before required checkbox rendered putting in ready wait until document ready or live bind on document level event reach through propogation


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -