asp.net mvc - Model binder does not convert json to IEnumerable<T> -
i sending json data controller action via jquery ajax post. ienumerable in action alway null.
is json wrong or why model binder not convert json ienumerable ?
public actionresult update(ienumerable<teststep> teststeps) { // } $.ajax({ url: '@url.action("update", "teststep")', type: 'post', data: [{ "errortext": "oh bad happended.", "unitid": "10" }, { "errortext": "you got man.", "unitid": "20"}], success: function (response) { debugger; if (response.success) { dlg.dialog("close"); // update ui } else { // reload dialog form show model/validation errors dlg.html(response); } } }); public class teststep { [hiddeninput(displayvalue = false)] public int unitid { get; set; } public string errortext { get; set; } // other props removed readability }
in order collections (arrays, ienumerables, etc) pass correctly through modelbinder action method, i've had set traditional: true option on ajax call:
$.ajax({ url: '@url.action("update", "teststep")', type: 'post', traditional: true, ...
Comments
Post a Comment