The existing .Net range attribute validator only accepts static string values. I would like to create a validator that accepts dynamic values. For example I would like the age range to be 16 years to 200. If I input the minimum birthday as 1996-today in a year from now the minimum age is now 17 and will continue to rise year after year. Is this possible or should I just validate this manually in the view model? Edit: I'm not using asp here, this is a desktop application.

有帮助吗?

解决方案

I fixed this by using a CustomValidationAttribute. This Attribute is basically just a static method that does the validating and I put the min/max birthdate values in the method. Unfortunately this is the only way I could find to deal with the issue of wanting the dates to be dynamic.

其他提示

DONE IT

 $("#YourField").data("val-range-max", $("#AFieldThatStoresTheMaxValue").value());

});

AFieldThatStoresTheMaxValue => could be a HiddenFor...

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top