Range annotation between nothing and 100?
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);
}
}
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.