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

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -