The Model:
public class MyObject
{
public IList<Entry> Entries;
}
public class Entry
{
public string Name { get; set; }
}
If I use the default EditorFor(model => model.Entries) the name/id values are:
<input type="text" value="" name="Entries[0].Name" id="Entries_0__Name">
If instead I want to create an EditorFor template like this:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<List<CMS.Models.MyObject>>" %>
<div class="list">
<%
for (int i = 0; i < Model.Count; i++)
{ %>
<div class="object" id="<%: i %>">
<%: Html.EditorFor(model => Model[i]) %>
<%: Html.ValidationMessageFor(model => Model[i]) %>
</div>
<% } %>
</div>
The emitted name/id values are:
<input type="text" value="" name="Entries.[0].Name" id="Entries__0__Name">
So the name has a period between the property name and [0] and the id has an extra underscore to the left of the index number. This doesn't work with the default model binder. Is there a way to do this that does work with the default model binder?