Range annotation between nothing and 100?

前端 未结 3 1588
春和景丽
春和景丽 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:52

    I guess you could override the Range object and add this behaviour.

    public class OptionalRange : RangeAttribute {
        public override bool IsValid(object value) {
            if (value == null || (int)value == 0) return true;
            return base.IsValid(value);
        }
    }
    

提交回复
热议问题