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; }
If you are concerned about the string looking nice you could do this:
This will have a default error message of:
If you're working with prices, I'm sure you can safely assume nothing will cost more than 1 trillion dollars.
I'd use:
Or if you really need it, just paste in the value of
Decimal.MaxValue
(without the commas):79,228,162,514,264,337,593,543,950,335
Either one of these will work well if you're not from Zimbabwe.
You can use:
This will impose a required minimum value of 0 (zero), and no maximum value.
You need DataAnnotationsExtensions to use this.
How about something like this:
That should do what you are looking for and you can avoid using strings.
I was going to try something like this:
The problem with doing this, though, is that the compiler wants a constant expression, which disallows
((double)0).ToString()
. The compiler will takeIt seems there's no choice but to put in the max value manually. I was hoping there was some type of overload where you didn't need to specify one.