Required attribute for an integer value

前端 未结 5 2201
遇见更好的自我
遇见更好的自我 2020-12-01 11:45

I have a viewmodel with an Id property

[Required]
public int Id { get; set; }

But I think this attribute is working only for string propert

5条回答
  •  自闭症患者
    2020-12-01 12:08

    If you are using a database, you should use the attributes [Key] and [DatabaseGenerated(DatabaseGenerated.Identity)] and Id shouldn't be NULLABLE.

提交回复
热议问题