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

前端 未结 16 1476
盖世英雄少女心
盖世英雄少女心 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 18:12

    The Id should be sent from the client as 0. The model does not have a problem with Id=0, this is the default of int. The problem is that he does not see the value coming from the client or it's coming with space or null. I have an input hidden that represents the Id (or in complex object NestedPropertyId/NestedProperty.Id) so I make sure it starts with a value of zero.

    
    
    
    

    Also when Ireset the form to Add New entity in the client side, I make sure to initialize the hidden with zero.

    Hope this helps somone.

    Efy

提交回复
热议问题