Name attribute works proper, but ShortName doesn't work.
[Display(Name = "Date of the transfer the task", ShortName = "Trans date")]
public DateTime TransferDate { get; set; }
Even when I delete Name attribute, ShortName is ignored ("TransferDate" displays in the column header).
In the view I do this:
@Html.DisplayNameFor(model => model.TransferDate)
If you look at the Description for the
ShortName
property on theDisplay
Attribute you'll see that it has a pretty limited scope out of the box:Of course, that doesn't limit you from leveraging that value on your Model Metadata, but there aren't any native helpers that do so.
Starting with MVC 2,
ModelMetadata
provides two methods to access the underlying data:FromStringExpression
andFromLambdaExpression
, so you don't really need to start from scratch in writing your own helper or extension method.If you hate writing HTML helper methods, you can do this all inline:
But it's also perfectly valid to add an extension method for consistency of access, deduplication of code, and improved error handling
And then use like any other helper method:
Further Reading:
[Display(name="")]
vs.[DisplayName("")]
attributes