javascript - How to get a @html.Checkbox to update a @html.dropdownList -
i have following checkbox:
@html.checkbox("norm", false, new { @class = "checkbox" })
once checked, want auto update dropdown
@html.dropdownlist("selectedcore", (selectlist)viewbag.coresheets)
the dropdown selectlist populated controller this,
viewbag.coresheets = new selectlist(db.coresheets, "sheetid", "abb");
so in summary, want click check box , have current dropdown value updated.
cheers,
b n j
try code
@html.checkbox("norm", false, new { @class = "checkbox",@onclick="clicknorm()" }) <script type="text/javascript"> function clicknorm(){ $.ajax({ url:'@url.action("loadselectedcorelist")' datatype:'json', success:function(res){ if(res && res.length>0){ $('#selectedcore).empty(); $.each(res,function(index,item){ $('#selectedcore').append(new option(item.abb,item.sheetid)); }); } } }); </script>
in coltroller
public actionresult loadselectedcorelist() { var selectedcorelist=.. return json(selectedcorelist, jsonrequestbehavior.allowget); }
Comments
Post a Comment