displayname attribute vs display attribute

Ghooti Farangi picture Ghooti Farangi · Mar 9, 2011 · Viewed 133.1k times · Source

What is difference between DisplayName attribute and Display attribute in ASP.NET MVC?

Answer

Darin Dimitrov picture Darin Dimitrov · Mar 9, 2011

DisplayName sets the DisplayName in the model metadata. For example:

[DisplayName("foo")]
public string MyProperty { get; set; }

and if you use in your view the following:

@Html.LabelFor(x => x.MyProperty)

it would generate:

<label for="MyProperty">foo</label>

Display does the same, but also allows you to set other metadata properties such as Name, Description, ...

Brad Wilson has a nice blog post covering those attributes.