开发者

Html.LabelFor does not use Name from DisplayAttribute

开发者 https://www.devze.com 2023-04-05 10:49 出处:网络
I have a model like this [MetadataType(typeof(PageMetadataMetadata))] public class PageMetadata : IPageMetadata {

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号