To my knowledge the html helper method DisplayNameFor
will take the value set in Display
attributed decorating the property in the expression passed to it, so for example for the following property.
[Display(Name = "Name", ResourceType = typeof(Resource))]
public string Name { get; set; }
If you have Resource entry as follows
Name: First Name
If you use DisplayNameFor as follows
@Html.DisplayNameFor(x => x.Name)
The displayed value will be
First Name
My question is, why don't you use the reference to the resource directly in razor so instead of using the DisplayNameFor
method, you just use the follow
@Resource.Name
In my opinion this is even better because it doesn't have the risk of magic strings used in the Display
attribute. So what value does DisplayNameFor
add to my code? and why should I use it?