If you do this in Asp.Net MVC 2 RC 2:
<% for (int count = 0; count < Model.Students.Count; count++ )
{ %><%=
Html.EditorFor(m => m.Students[count]) %><%
}
%>
where Students is a List<Student>, and it produces this:
<input class="text-box single-line" id="Students_0__Name" name="Students[0].Name" type="text" value="Harry" />
<input class="text-box single-line" id="Students_1__Name" name="Students[1].Name" type="text" value="Tom" />
<input class="text-box single-line" id="Students_2__Name" name="Students[2].Name" type="text" value="Richard" />
Is there a way to remove the name=”” attribute without breaking the model binding when they post?
In html, for an element within a form to be posted, it requires a name attribute. So, no, there is no way to remove the name attribute.
Here’s where it is defined in the official definition…
http://www.w3.org/MarkUp/html-spec/html-spec_8.html
🙂