Search code examples
c#.netasp.net-mvcdata-annotations

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

  • It 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.

    [Range(typeof(decimal), "0", "79228162514264337593543950335")]
    public decimal Price { get; set; }