Frage

What is the difference between these 2 Display attributes?

[Required]
[DisplayName("Status")]
[Display(Name = "Status")]
public string StatusName;

These are inside a buddy metadata class using mvc5 and EF 6 in VS2012.

The first one will throw this message.

enter image description here

War es hilfreich?

Lösung

Possible duplicate:

displayname attribute vs display attribute

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top