How to specify a min but no max decimal using the range data annotation attribute?
I would like to specify that a decimal field for a price must be >= 0 but I don't really want to impose a max value.
Here's what I have so far...I'm not sure what the correct way to do this is.
[Range(typeof(decimal), "0", "??"] public decimal Price { get; set; }
Solution 1:
How about something like this:
[Range(0.0, Double.MaxValue, ErrorMessage = "The field {0} must be greater than {1}.")]
That should do what you are looking for and you can avoid using strings.
Solution 2:
If you are concerned about the string looking nice you could do this:
[Range(0, Double.PositiveInfinity)]
This will have a default error message of:
The field SuchAndSuch must be between 0 and Infinity.