Wrap Your EditorTemplates
A really cool feature in Razor is the EditorTemplate's ability to use Layouts. Just like regular Views, you can apply the a Layout. For example, a regular Textbox template:
This file contains hidden or bidirectional
Unicode text that may be interpreted or
compiled differently than what appears
below. To review, open the file in an
editor that reveals hidden Unicode
characters.
Learn more about bidirectional Unicode
characters
| @model string | |
| @{ | |
| Layout = "_Layout.cshtml"; | |
| } | |
| @Html.TextBoxFor(x => x) |
Would then be used with _Layout.cshtml:
This file contains hidden or bidirectional
Unicode text that may be interpreted or
compiled differently than what appears
below. To review, open the file in an
editor that reveals hidden Unicode
characters.
Learn more about bidirectional Unicode
characters
| <div class="editor-label"> | |
| @Html.LabelFor(x => x) | |
| </div> | |
| <div class="editor-field"> | |
| @RenderBody() | |
| @if (ViewData.ModelMetadata.IsRequired) | |
| { | |
| <text><span class="required">*</span></text> | |
| } | |
| @Html.ValidationMessageFor(x => x) | |
| </div> |