I believe that input tags associated with items in the collection (when the model itself is not a collection) should have an index in the name attribute before you can bind the published data to the view model. This is how I usually do it ...
<% for (int i=0; i<Model.TeamMembers.Count; i++) { %> <div class="editor-field"> <%: Html.EditorFor(m => m.TeamMembers[i].FirstName)%> </div> <div class="editor-field"> <%: Html.EditorFor(m => m.TeamMembers[i].LastName)%> </div> <% } %>
I also used the template suggested by Shea, but I have another code that tries to make it display brackets / indexes.
<% foreach (var member in Model.TeamMembers) { %> <%: Html.EditorFor(x => member, "TeamMember", "TeamMembers["+(member.Number-1)+"]", new { MemberTypes = Model.GetMemberTypes(member.MemberType.TypeId) })%> <% } %>
Here is an old but still relevant article by Phil Haack on this topic.
source share