This is not very good, but you can use EditorTemplates and create _layout.cshtml that uses all your templates. Then use this to output / display the DisplayName :
<div class="form-group"> <label for="@ViewData.ModelMetadata.PropertyName"> @Html.Raw(ViewData.ModelMetadata.GetDisplayName()) </label> @RenderBody() @Html.ValidationMessageFor(x => x) </div>
A major drawback of this is the creation of EditorTemplates for each of your types, such as the string.cshtml template:
@model string @{ Layout = "_Layout.cshtml"; } @Html.TextBoxFor(x => x, new { @class="form-control" })
A little off topic, but this route allows me to encapsulate the wrapping of HTML around the elements of my form, so my forms in the views look very simple:
<fieldset> @Html.EditorFor(x => x.Email) @Html.EditorFor(x => x.Address1) @Html.EditorFor(x => x.Address2) @Html.EditorFor(x => x.City) </fieldset>
mxmissile
source share