robh,
你很难从你的问题知道你是否正在寻找您的项目中的“通用”或具体的解决方案。因此,我打算一次解决通用作品,解决方案无处不在。
这需要采取几个步骤(约定优于配置)。基本上这里的真实需要什么:
- 下创建新文件夹 '则须─>共享称为编辑模板'
- 创建一个新的usercotrol(ASCX)文件 下那个叫 'string.ascx'
现在,定义ASCX文件按:
<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<string>" %>
<div class="editor-label">
<%= Html.LabelFor(model => model) %>
</div>
<div class="new-editor-field">
<%= Html.TextBoxFor(model => model) %>
<%= Html.ValidationMessageFor(model => model) %>
</div>
这将ñ ow使所有基于'string'的EditorFor()调用使用这个'模板'。只需让该类的“新编辑字段”反映出该字段所需的CSS样式即可。显然,根据自己的要求做饭(即你可能不希望LabelFor达等)。
希望这有助于 - 我不得不说,这只是其中一个方法来做到这一点(但是我的首选方式)。
享受EditorFor的
吉姆
可能的dup [asp.net mvc 2 EditorFor()和html属性](http://stackoverflow.com/questions/1625327/asp-net-mvc-2-editorfor-and-html-properties) – RedFilter 2010-08-05 20:22:48
是EditorFor一个“要求“或者你打开试图'TextBoxFor' /'TextAreaFor'? – 2011-07-13 17:18:35
我不敢相信你不能以一种整洁的方式做到这一点! – 2013-01-18 15:49:43