2013-02-11 13 views
0

我有以下看法:Html.EditorFor的模型,而不是一個性質,在MVC4

<fieldset> 
     <legend>CreateCardViewModel</legend> 

     <div class="editor-field"> 
      @Html.EditorFor(model => model.SetId) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.DateCreated) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.DateCreated) 
      @Html.ValidationMessageFor(model => model.DateCreated) 
     </div> 

     <div class="editor-label"> 
      @Html.LabelFor(model => model.IsReady) 
     </div> 
     <div class="editor-field"> 
      @Html.EditorFor(model => model.IsReady) 
      @Html.ValidationMessageFor(model => model.IsReady) 
     </div> 

     @foreach (var side in Model.Sides) 
     { 
      @Html.EditorFor(model => model.Sides[side.SideId]) 
     } 


     <p> 
      <input type="submit" value="Create" /> 
     </p> 
    </fieldset> 

這個片段:爲兩岸模型的所有屬性

@foreach (var side in Model.Sides) 
      { 
       @Html.EditorFor(model => model.Sides[side.SideId]) 
      } 

顯示可編輯的字段。定義此列表的哪些字段應該可編輯的最合適的方式是什麼?

回答

1

for循環改用:

@for (int i = 0; i < Model.Sides.Count; i++) { 
    @Html.EditorFor(x => x.Sides[i]) 
} 
+0

感謝。在視圖中隱藏每一方的某些屬性,你認爲最好的方法是什麼?我可以在editorFor幫手中指定字段嗎? – RobVious 2013-02-11 14:37:08

0

從頭開始 - 我意識到,我可以做到以下幾點:

@for (int i = 0; i < Model.Sides.Count; i++) 
     { 
      @Html.EditorFor(x => x.Sides[i].Content) 
      @Html.EditorFor(x => x.Sides[i].IsFront) 
      @Html.EditorFor(x => x.Sides[i].Stage) 
     } 
相關問題