Html.LabelFor does not use Name from DisplayAttribute
I have a model like this
[MetadataType(typeof(PageMetadataMetadata))]
public class PageMetadata : IPageMetadata {
public virtual string Name { get; set; }
}
and my metadata class like this
internal class PageMetadataMetadata {
[Display(Name = "Title", Order = 10, Prompt开发者_JS百科 = "My awesome page")]
[Required(ErrorMessage = "Name_Required")]
public virtual string Name { get; set; }
}
When I use this model in my view I cannot get it to use the name from my DisplayAttribute?
@Html.LabelFor(model => model.CurrentModel.Metadata.Name)
With DisplayAttribute, you have to set also the ResourceType
. If you don't want to use localization try using DisplayNameAttribute.
精彩评论