asp.net-mvc-3 – 如何创建通用的MVC3编辑器模板?

我在我的模型模板中广泛使用以下代码片段.
<div class="control-group">
    @Html.LabelFor(model => model.FirstName)
    <div class="controls">
        @Html.TextBoxFor(model => model.FirstName,new { @class = "span3" })
        @Html.ValidationMessageFor(model => model.FirstName)
    </div>
</div>

是否可以将其一般性地封装在编辑器模板中,这样我就可以使用Html.EditorFor(…)而不需要使用自定义扩展?

解决方法

Is it possible to encapsulate this generically in an editor template
so I can use Html.EditorFor(…) without resorting to a custom
extension?

当然:

〜/查看/共享/ EditorTemplates / Foo.cshtml:

<div class="control-group">
    @Html.Label("")
    <div class="controls">
        @Html.TextBox("",ViewData.TemplateInfo.FormattedModelValue,new { @class = "span3" })
        @Html.ValidationMessage("")
    </div>
</div>

接着:

@Html.EditorFor(x => x.FirstName,"Foo")

要么:

[UIHint("Foo")]
pubilc string FirstName { get; set; }

接着:

@Html.EditorFor(x => x.FirstName)

相关文章

这篇文章主要讲解了“WPF如何实现带筛选功能的DataGrid”,文...
本篇内容介绍了“基于WPF如何实现3D画廊动画效果”的有关知识...
Some samples are below for ASP.Net web form controls:(fr...
问题描述: 对于未定义为 System.String 的列,唯一有效的值...
最近用到了CalendarExtender,结果不知道为什么发生了错位,...
ASP.NET 2.0 page lifecyle ASP.NET 2.0 event sequence cha...