0

我有以下看法:

<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 模型的所有属性的可编辑字段。定义该列表的哪些字段应该是可编辑的最合适的方法是什么?

4

2 回答 2

1

改用 for 循环:

@for (int i = 0; i < Model.Sides.Count; i++) {
   @Html.EditorFor(x => x.Sides[i])
}
于 2013-02-11T14:29:45.177 回答
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)
        }
于 2013-02-11T14:40:35.243 回答