ASP.NET MVC5: Want to update several items in Collection with model binding

戏子无情 提交于 2019-12-03 13:29:23

You need to index your collection with a for rather than a foreach in order for the ModelBinder to pick it up:

for (var i = 0 ; i < Model.Count(); i++)
    {
        @Html.HiddenFor(modelItem => modelItem[i].Id)
        @Html.EditorFor(modelItem => modelItem[i].FirstName)
        @Html.ValidationMessageFor(modelItem => modelItem[i].FirstName)
        @Html.EditorFor(modelItem => modelItem[i].LastName)
        @Html.ValidationMessageFor(modelItem => modelItem[i].LastName)
        @Html.EditorFor(modelItem => modelItem[i].Birth)
        @Html.ValidationMessageFor(modelItem => modelItem[i].Birth)
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!