Is GreaterThanIf currently possible?

Jun 12, 2012 at 2:40 PM

Hello,

First of all, thank you for this library. It is extremely helpful in many scenarios and is a constant tool in my toolkit.

Is there any straightforward way to implement a GreaterThanIf scenario using existing mechanisms? Here is what I'm doing/would like to do:

  • In my application I have a scenario where I show and hide an "end date" field based on the selected value of a dropdown menu.
  • I use RequiredIf to guarantee that the end date is required if the dropdown value is "auction".
  • When the end date is visible I also want to guarantee that it is greater than the start date.
  • However, when I add both the required and greaterthan attributes to my end date field, the greaterthan always fires, regardless of whether or not the field is required.
  • I'd like to combine these attributes such that the greaterthan functionality only fires if the field is required

Thanks in advance,

Jason



Coordinator
Jun 12, 2012 at 2:47 PM

You will have to build a custom validator for that. Here is an example:

http://www.nickriggs.com/posts/build-model-aware-custom-validation-attributes-in-asp-net-mvc-2/