Required attribute for an integer value

前端 未结 5 2210
遇见更好的自我
遇见更好的自我 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:07

    Use the Range Attribute.

    Set minimum to 1 and maximum to int.MaxValue

    [Range(1, int.MaxValue, ErrorMessage = "Value for {0} must be between {1} and {2}.")]
    

提交回复
热议问题