问题
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