DataAnnotation for Required property

后端 未结 4 854
生来不讨喜
生来不讨喜 2020-12-05 00:24

First it works, but today it failed!

This is how I define the date property:

[Display(Name = \"Date\")]
[Required(ErrorMessage = \"Date of Submissio         


        
4条回答
  •  渐次进展
    2020-12-05 00:44

    Okay. Though I have not complete understood this thing. A workaround is found.

    In Global.asax:

    GlobalConfiguration.Configuration.Services.RemoveAll(
        typeof(System.Web.Http.Validation.ModelValidatorProvider),
        v => v is InvalidModelValidatorProvider);
    

    I found it in the Issue Tracker in aspnetwebstack. Here is the link to the page:

    Overly aggressive validation for applying [DataMember(IsRequired=true)] to required properties with value types

    If anyone can tell us why it is like this, please post your insight as answers. Thank you.

提交回复
热议问题