ASP.NET MVC 4 – for loop posts model collection properties but foreach does not

the problem is not with the IEnumerable or the IList it the way you are rendering the collection in your view.

@for(var i = 0;i < Model.People.Count;i++)
{
    <tr>
        <td>@Html.TextBoxFor(m => Model.People[i].Name)</td>
        <td>@Html.TextBoxFor(m => Model.People[i].Age)</td>
    </tr>
}

Observe that with each list item you are appending a continuous index which enables the model binder to do its magic

A good read

Leave a Comment