jquery - How to save radiobutton selected value in mvc when radio buttons are binded with database values? -
i have radiobutton in view. binding values radiobutton db. after selection using jquery want send selected value of radiobutton controller. here view code.
@{ viewbag.title = "permmapping"; layout = "~/views/shared/_layoutc3card.cshtml"; list<c3card.dal.edmodel.ts_grp_perm_mapping> tmgrp1 = (list<c3card.dal.edmodel.ts_grp_perm_mapping>)viewbag.selectedcheckboxes; } script type="text/javascript"> $.ajax({ type: 'post', url: '/grpcontroller/savenewuser', data: { usr_groupid: $('#ddl_group').val() }, datatype: 'json', success: function (data) { alert('user saved successfully.'); $('#tbluserregistration').empty(); } }); </script>
this table
<table id="tbluserregistration"> <tr> <td> <div class="form-box form-box-default"> @html.dropdownlist("ddl_group", viewbag.list selectlist, "--select--") </div> <td> </tr> <tr> <td> <div> <ul> @{ int row = 0; } @foreach (c3card.dal.edmodel.tm_perm_level obj in tmgrp) { <li>@html.radiobutton("mid",obj.perm_id)@obj.perm_levelname</li> } </ul> </div> </td> </tr> </table>
here want selected radiobutton id want send controller using javascript.
this controller code.
public actionresult index() { list<tm_perm_level> tm_perm_level = grppermbal.getallpermtype(); viewbag.chklist = tm_perm_level; // list<tm_grp_group> tm = userservice.getallgroup(); viewbag.list = new selectlist(grppermbal.getallgroup(), "grp_id", "grp_name"); return view("~/views/grpcontroller/permmapping.cshtml"); } public jsonresult savenewuser(int usr_groupid,string usr_doctypeids) { list<ts_grp_perm_mapping> ts_grp_perm_mapping = grppermbal.getdata(usr_groupid); viewbag.selectedcheckboxes = ts_grp_perm_mapping; int result = grppermbal.savenewuser(usr_groupid,usr_doctypeids); return json(result, jsonrequestbehavior.allowget); }
to value of selected radio button can use
var selected = $('[name="mid"]:checked').val());
so ajax data
options becomes
data: { usr_groupid: $('#ddl_group').val(), usr_doctypeids: selected },
which bind value of selected option string usr_doctypeids
parameter in savenewuser()
method
Comments
Post a Comment