I am trying to leverage DataAnnotation values in ASP.NET MVC Index view. Interesting, code generator uses field names (eg., BlogPost) as opposed to Html.LabelFor(m =&g
In MVC 4, the HtmlHelper extensions in the DisplayNameExtensions class allows the following (this is the default scaffolding of a list with column headings)
@model IEnumerable
@Html.DisplayNameFor(model => model.Bar)
@foreach (var item in Model) {
@Html.DisplayFor(modelItem => item.Bar)
...
This is because DisplayNameFor has overloads for both TModel and IEnumerable:
public static MvcHtmlString DisplayNameFor
(this HtmlHelper> html,
Expression> expression);
public static MvcHtmlString DisplayNameFor
(this HtmlHelper html,
Expression> expression);
- 热议问题