javascript - Form with ListBox is submitted empty when submitted onchange -


working on asp.net mvc razor, problem straightforward: have form select element submit via javascript when selection changes. form empty on submission. selected value not enclosed, formcollection empty. there's silly mistake i'm making somewhere, i've wasted 2 hours on getting work, different perspective might help.

the code in cshtml view:

    @using (html.beginform("setfilter", "home", formmethod.get, new { @id = "filter"}))     {         @html.dropdownlist("tags", new selectlist(model.filters, "value", "text"), htmlattributes: new { @id = "topnav_filters", onchange = "submitfilter()" });     } 

the function doing submitting:

function submitfilter() {     var debug = $("#filter");     $("#filter").submit(); } 

and controller action supposed data (doesn't yet, serves set breakpoint , check if i'm getting anything):

    public actionresult setfilter(formcollection form)     {         return view();     } 

stephenmucke brought above, part of problem. controller action did in fact @ first:

 public actionresult setfilter(string tag) {     return view(); } 

but tag null, tried other things. however, notice variable name "tag", not "tags". changing "tags" did indeed fix problem.

i dumbfounded this. never have expected binder attempt match name of input element actual name of variable (a thing until considered meaningless program ran through compiler). supposed go order or maybe try discern datatype or somesuch. understand mapping of property names input elements in bind[] command. i'd never have expected thing match variable names...


Comments