“The Id field is required” validation message on Create; Id not set to [Required]

前端 未结 16 1471
盖世英雄少女心
盖世英雄少女心 2020-12-07 17:18

This is happening when I try to create the entity using a Create style action in Asp.Net MVC 2.

The POCO has the following properties:

public int Id          


        
16条回答
  •  佛祖请我去吃肉
    2020-12-07 17:55

    You can disable this implicit validation by setting the AddImplicitRequiredAttributeForValueTypes option on the DataAnnotationsModelValidatorProvider by adding the following to your Application_Start:

    DataAnnotationsModelValidatorProvider.AddImplicitRequiredAttributeForValueTypes = false;
    

    Further Reading:

    • Unrequired property keeps getting data-val-required attribute
    • ASP.NET MVC optional field being treated as required
    • Why MVC Model Binder set required for int, long values?

提交回复
热议问题