【发布时间】:2012-11-13 22:07:56
【问题描述】:
我用
渲染我的 ViewModel创建.cshtml:
@using (Html.BeginForm("Create","TestTemplate")) {
@Html.EditorForModel()
}
我不喜欢输出内容,因为所有的 div 都在另一个之下。如果我想要一个水平布局,其中一个 div 向左浮动到另一个 div?
当我的 Create.cshtml 视图中没有 html 时,如何使用 EditorForModel() 助手修改此类布局更改?
更新:
为什么我必须创建两个视图。在我在另一个 EditorTemplate-view 中调用 @Html.EditorForModel() 的那个中,我做了所有我也可以通过 EditorFor( x => x....) 在第一个视图中做的布局工作?这对我来说似乎很奇怪。
【问题讨论】:
-
@Simon 我重新表述了我的问题。
-
EditorTemplates 允许您在需要时为同一模型重复使用布局。它省去了您为同一个模型一遍又一遍地手动编写
@Html.EditorFor(x => x...)、@Html.TextBoxFor(x => x...)。 -
你试过Object.cshtml吗?在这里查看github.com/MattHoneycutt/Fail-Tracker/tree/master/…
标签: c# asp.net-mvc-4 editorformodel