Model Bind to a List<> when Posting JavaScript Data Object

为君一笑 提交于 2019-12-06 22:12:43

In the end, this worked:

var valuesArray = objCheckBoxes.map(function()
{
    return $.getAttributes($(this));
});

var obj = new Array();
$.each(valuesArray, function(item) { obj.push($(this)[0]); });

$.each(obj, function(i)
{
    // basically I take the rule where you need to append
    // the index to the type, and I apply it here.
    data["configuredFactsheets[" + i + "].configuredFactsheetId"] = $(this).attr("configuredFactsheetId");
});

Note: read about $.getAttributes

An alternative is to post:

?myValues=1&myValues=2&myValues=3

And accept it as an IEnumerable

public ActionResult DoSomething(IEnumerable<int> myValues) {
    ...
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!