The result of [DisplayName("foo")] and [Display(Name="foo")] for @Html.LabelFor(x => x.MyProperty) is same. both generate <label for="MyProperty">foo</label>. what is the advantage of DisplayName?
The result of [DisplayName(foo)] and [Display(Name=foo)] for @Html.LabelFor(x => x.MyProperty) is same. both generate
Share
Displayattribute should be preferred overDisplayNameattribute. The former one comes formDataAnnotationsnamespace and exposes more properties than the later one, ie. ShortName, Prompt, GroupName, Order, Description, which are used byDataAnnotationsMetadataProvider.Most importantly,
DisplayNameaccepts only literals, whileDisplayaccepts resource type and key, which can be used to provide translations using separate resource files (resx).