0

如果您在 Asp.Net MVC 2 RC 2 中执行此操作:

<% for (int count = 0; count < Model.Students.Count; count++ )
   {                                              %><%= 
      Html.EditorFor(m => m.Students[count])      %><%
   } 
%>

其中 Students 是 a List<Student>,它会产生:

<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" />

有没有办法在发布时删除 name="" 属性而不破坏模型绑定?

4

1 回答 1

2

在 html 中,对于要发布的表单中的元素,它需要一个 name 属性。所以,不,没有办法删除 name 属性。

这是官方定义中定义的地方......

http://www.w3.org/MarkUp/html-spec/html-spec_8.html

:-)

于 2010-02-22T21:17:44.150 回答