views:

33

answers:

1

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?

+2  A: 

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

:-)

Russell Giddings
It seems silly to have both a name and an id. Is it possible to remove the id without ill effects in MVC?
Dr. Zim
The ID attribute is primarily used on the client side within JavaScript. However, there is no need to have it from the perspective of being posted back to the server in Asp.NET MVC.
Russell Giddings