So I have a Collection of User objects, which should be mass-editable (edit many users at the same time). I\'m saving the user input to the database using Entity Framework.
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)
}