Range annotation between nothing and 100?

前端 未结 3 1587
春和景丽
春和景丽 2021-01-17 09:14

I have a [Range] annotation that looks like this:

[Range(0, 100)]
public int AvailabilityGoal { get; set; }

My webpage looks like this:

3条回答
  •  北荒
    北荒 (楼主)
    2021-01-17 10:09

    You shouldn't have to change the [Range] attribute, as [Range] and other built-in DataAnnotations validators no-op when given an empty value. Just make the property itself of type int? rather than int. Non-nullable ValueType properties (like int) are always automatically required.

提交回复
热议问题