在集合上使用EditorFor()时,是否可以返回当前迭代的索引?

时间:2010-07-14 14:58:26

标签: asp.net-mvc-2

我正在使用EditorFor()

<%: Html.EditorFor(model => model.documentInfo.destinations)%>

而不是foreach

<% foreach (var item in Model.documentInfo.destinations)
   {
       Html.RenderPartial("Document/Destination", item);
   }
%>

是否可以获取EditorFor()显示哪个项目的数字索引?

编辑:我想使用编辑器模板中的索引为模板中的字段生成自定义增量名称/ ID。

2 个答案:

答案 0 :(得分:1)

尝试创建IList类型的强类型模板。

<%@Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<IList>" %>

<% for(int i = 0; i < Model.Count; i++) { %>
    <h1><%:Model[i]%></h1>
<% } %>

答案 1 :(得分:0)

似乎不,您无法访问使用EditorFor()生成的集合中字段的数字索引。