2011-12-29 58 views
2

在ASP.NET MVC中,使用EditorTemplates时有没有办法获得循环索引?在过去,当我需要知道模型中某个元素的索引时,我放弃使用EditorTemplates来支持基本视图中的for循环。我想知道是否有一种方法来获取元素的索引,同时仍然使用EditorTemplates。在ASP.NET MVC中,使用EditorTemplates时有没有办法获得循环索引?

我的for循环示例:

 @{int contentIndex = 0;} 
     @foreach (var item in Model.Content) 
     { 
      <p id="[email protected](contentIndex)"> 
       @Html.TextArea("Content["+contentIndex+"]", item) 
      </p> 
      contentIndex++; 
     } 

看我怎么使用contentIndex段落ID?我希望能够使用EditorTemplate而不是for循环来做到这一点。这可能吗?

回答

相关问题