How do I get the [Display(Name=\"Some Title\")] DataAnnotations \"Some Title\" rendered in the List scaffold view\'s output?
I create a strongly typed l
//MVC4 has the DisplayNameFor Extensions
public static class HtmlHelperExtensions
{
public static MvcHtmlString DisplayNameFor(this HtmlHelper> helper, Expression> expression)
{
return DisplayNameFor(expression);
}
public static MvcHtmlString DisplayNameFor(this HtmlHelper helper, Expression> expression)
{
return DisplayNameFor(expression);
}
private static MvcHtmlString DisplayNameFor(Expression> expression)
{
var metadata = ModelMetadata.FromLambdaExpression(expression, new ViewDataDictionary());
var htmlFieldName = ExpressionHelper.GetExpressionText(expression);
string s = metadata.DisplayName ?? (metadata.PropertyName ?? htmlFieldName.Split(new char[] { '.' }).Last());
return new MvcHtmlString(HttpUtility.HtmlEncode(s));
}
}