Range annotation between nothing and 100?

前端 未结 3 1579
春和景丽
春和景丽 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 09:55

    This seems to work as (pretty) well:

    [Range(Double.NaN, 20)]
    public byte? Amount { get; set; }
    

    The lower limit is not checked upon. Not so handy if you want to check null || >= 0. Off course server-side validation goes hand-in-hand with client-side validation where this (< 0) can be checked upon.

提交回复
热议问题