jquery - Error when Serializing Js array to MVC model collection -
i have jquery code creating storing collection of checked checkboxes boxes array. array stored value of hidden field on form id of 'checkedsubgroups. hidden field has been given name of list controller:
model:
public ilist<int> subtgrouppkids { get; set; } hidden field on form:
<input type="hidden" id="checkedsubgroups" name="subgrouppkids" value="[]" /> jquery adding items array.
$(".subgroupcheckboxes").on("click", function() { if ($(this).is(':checked')) { var subgrouparray = json.parse($("#checkedsubgroups").val()); subgrouparray.push($(this).attr('data-subgrouppkid')); $("#checkedsubgroups").val(json.stringify(subgrouparray)); if add couple of items array looks (from debugger):
[15330,16657] [prototype]: [] length: 2 [0]: "15330" [1]: "16657" i serialize form using jquery's .serialize method.
however binding error fails convert array list.
the value '["15330","16657"]' not valid subgrouppkids. where going wrong?
you need de-serialize json array in controller
var deserializer = new javascriptserializer(); subgrouppkids = deserializer.deserialize<list<int>>(serializeddata "data submitted controller");
Comments
Post a Comment