Range annotation between nothing and 100?
Posted
by aticatac
on Stack Overflow
See other posts from Stack Overflow
or by aticatac
Published on 2010-05-26T13:19:11Z
Indexed on
2010/05/26
13:21 UTC
Read the original article
Hit count: 265
asp.net-mvc
|dataannotations
Hi
I have a [Range] annotation that looks like this:
[Range(0, 100)]
public int AvailabilityGoal { get; set; }
It works as it should, I can only enter values between 0 and 100 but I also want the input box to be optional, the user shouldn't get an validation error if the input box is empty. If the user leaves it empty it should make AvailabilityGoal = 0 but I don't want to force the user to enter a zero.
I tried this but it (obviously) didn't work:
[Range(typeof(int?), null, "100")]
Is it possible to solve this with Data Annotations or in some other way?
Thanks in advance.
Bobby
© Stack Overflow or respective owner