Asp.net mvc Html.editor,用于MVC4中的模型,而不是属性
我有以下看法:Asp.net mvc Html.editor,用于MVC4中的模型,而不是属性,asp.net-mvc,asp.net-mvc-3,asp.net-mvc-4,Asp.net Mvc,Asp.net Mvc 3,Asp.net Mvc 4,我有以下看法: <fieldset> <legend>CreateCardViewModel</legend> <div class="editor-field"> @Html.EditorFor(model => model.SetId) </div> <div class="editor-label">
<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>
显示侧面模型所有特性的可编辑字段。定义此列表中哪些字段应可编辑的最合适方法是什么 改用for循环:
@for (int i = 0; i < Model.Sides.Count; i++) {
@Html.EditorFor(x => x.Sides[i])
}
@for(int i=0;ix.Sides[i])
}
我意识到我可以做到以下几点:
@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)
}
@for(int i=0;ix.Sides[i].Content)
@EditorFor(x=>x.Sides[i].IsFront)
@EditorFor(x=>x.Sides[i].Stage)
}
谢谢。就隐藏视图中每一方的某些属性而言,您认为最好的方法是什么?我可以在editorFor助手中指定字段吗?
@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)
}