How can I customize the unobtrusive validation in ASP.NET MVC 3 to match my style?

In my code instead of using $.validator.setDefaults I access the form validator using $("#form_selector").data('validator') and then change the settings.

$(function () {

    var validator = $("#form_selector").data('validator');
    validator.settings.errorPlacement = function(error,element) {
        alert('errorPlacement');
    };

});

See if it works for you.


I had the same issue, but realized that the Unobtrusive plugin was actually casuing the issue, it will override any options you set! The trick is to have your code written/included in the following order:

  1. The validate plugin
  2. Your custom code & options
  3. The unobtrusive plugin

Any other order and this won't be set correctly!