Let's say I have this view model:
public class MyModel { [Range(0, 999, ErrorMessage = "Invalid quantity")] public int Quantity { get; set; } }
Now, for specific instances of this model the range of valid values will change: some may not be 0, some may not be higher than 5. The min/max values for the valid ranges are coming from the DB and can change anytime.
How do I change the min/max properties of the RangeAttribute on the fly? Or what it the best way to validate my scenario?
Best Answer
Something along the lines of this might be more what your after...
ViewModel:
Library class or elsewhere:
From: MVC unobtrusive range validation of dynamic values