我有以下观点:
<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])
}
显示Sides模型的所有属性的可编辑字段。定义哪个字段应该可以为此列表编辑的最合适方法是什么?
答案 0 :(得分:1)
改为使用for循环:
@for (int i = 0; i < Model.Sides.Count; i++) {
@Html.EditorFor(x => x.Sides[i])
}
答案 1 :(得分: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)
}