Applying [JsonIgnore] to property causes DataAnnotation attributes to be “lost”

自作多情 提交于 2019-12-08 11:52:18

问题


Given the following code:

    [JsonIgnore]
    [Display(Name = "Loan Cap")]
    public virtual string SomeProperty { get; protected set; }

When the DataAnnotationsModelMetadataProvider.CreateMetadata is called by ASP.NET MVC to fulfil the following call:

@Html.DisplayNameFor(model => model.SomeAttribute)

The list of attributes handed to CreateMetadata does not include the [Display] attribute (or the [JsonIgnore] for that matter). If I remove the [JsonIgnore] then the [Display] gets found and passed to CreateMetadata. Anyone have any idea why this is happening?

来源:https://stackoverflow.com/questions/11941223/applying-jsonignore-to-property-causes-dataannotation-attributes-to-be-lost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!