i have an action and want to do some simple check on param
ActionResult Test([Range(0,10)] int i)
{
// ModelState.IsValid is always true, i want it to be false if i > 10 or i < 0
}
anyway to fix this or work around it or any alternatives provided by MVC?
I thought of just checking the data annotation attribute definition before giving you some alternate options. I surprised to see that the
AttributeUsageis defined in such that you can apply to the method parameters as well and unfortunately it not worked as i tried myself. Though I’m not sure why they have allowed this parameter to method parameters (I see it’s valid but not working)Regarding alternate options you could try this,