Search code examples
asp.net-mvc-3customvalidatorfluentvalidation

Conditional validation in MVC3


In MVC3, there are a way to add or stop validation in a field depending on the value of a drop-drown list with JQuery? I have been trying with Fluent Validation, but with no luck.


Solution

  • Are you using unobtrusive validation? Is so, look at the html and you will see that there are some html5 attributes on your input, something like this:

    <input name="product" id="product" data-val="true" data-val-required="Product is required" />
    

    I suppose you could use jQuery to remove the data-val attribute and then the jQuery Validator will skip this item.

    $("#product").data("val", false);
    

    Well, that's my guess, try it yourself.