jquery - ASP.NET CheckBoxFor generates hidden field messes up ajax submit -
so default @html.checkboxfor
going generate hidden field after original field, like
<input name="xxx" id="xxx" type="checkbox" .... data-val="true" value="true"/> <input name="xxx" type="hidden" value="false"/>
when ajax submit $(form).serialize()
post body contain 2 xxx fields if checkbox checked. (xxx=true&&xxx=false
) expected. modelstate.isvalid
returns false , error
system.invalidoperationexception: parameter conversion type 'system.collections.generic.list`1[system.string]' type 'system.boolean' failed because no type converter can convert between these types
how can fix this??
update: happening webapi controller, doing regular model binding
[httppost] public void mymethod(mymodel model) { if ( !modelstate.isvalid ) throw new httpresponseexception( httpstatuscode.badrequest ); }
Comments
Post a Comment