MVC 3 Razor EditorTemplate/DisplayTemplate母版页

mat*_*to0 4 razor asp.net-mvc-3

有没有人想出如何使用Razor的Editor和DisplayTemplates母版页,类似于Brad Wilson在这里记录的内容?

http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-5-master-page-templates.html

谢谢

mat*_*to0 7

这并没有像我原先想象的那样复杂.

一个小小的免责声明:这不是一个完整的审查,只是一个简单的例子,只是为了让它工作.

这就是我做的:

〜/查看/共享/ _TemplateMaster.cshtml

<div class="editor-label">
    <label for="@ViewData.ModelMetadata.PropertyName">@ViewData.ModelMetadata.GetDisplayName()</label>
</div>
<div class="editor-field">
    @RenderSection("DataContent")
</div>
<div>
    @Html.ValidationMessage("")
</div>
Run Code Online (Sandbox Code Playgroud)

〜/查看/共享/ EditorTemplates/String.cshtml

@{
    Layout = "~/Views/Shared/_TemplateMaster.cshtml";
}

@section DataContent
{
    @Html.TextBox("", ViewData.TemplateInfo.FormattedModelValue, new { @class = "" })
}
Run Code Online (Sandbox Code Playgroud)