我正在使用EditorFor()
<%: Html.EditorFor(model => model.documentInfo.destinations)%>
而不是foreach
<% foreach (var item in Model.documentInfo.destinations)
{
Html.RenderPartial("Document/Destination", item);
}
%>
是否可以获取EditorFor()显示哪个项目的数字索引?
编辑:我想使用编辑器模板中的索引为模板中的字段生成自定义增量名称/ ID。
答案 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()
生成的集合中字段的数字索引。