Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MicrosoftMvcValidation.js VS jquery.validate.js (Bassistance)

Tags:

asp.net-mvc

In a previous MVC 2.0 application, I included (in my Site.Master) a reference to the CDN file of jquery.validate.min.js for all my client-side validation.

I’m now creating an MVC 3.0 project and I’m a bit confused with the amount of articles written about “how to use client-side validation using MicrosoftMvcValidation.js”.

In most (if not all) articles, when I see a reference to MicrosoftMvcValidation.js I also see a reference to jquery.validate.js which is kind of confusing (considering, in the past, I’ve only used bassistance’s file).

So my questions are:

  • What is the difference between these two files?
  • Are there any known issues/benefits in using one over the other?
  • Inside the “Scripts” folder, by default, it looks like both files are there but why? Do they give us the choice or do they work hand in hand?

Any help shedding some light on this would be great!

Thanks in advance!

like image 676
Vlince Avatar asked Dec 08 '11 14:12

Vlince


2 Answers

MVC3 supports two modes of client-side validation:

  • Classical validation using MicrosoftMvcValidation.js
    To enable this, call Html.EnableClientValidation() before Html.BeginForm().

  • Unobtrusive validation using jquery.validate.js and jquery.validate.unobtrusive.js (new to MVC3)
    To enable this, add the following settinsg to Web.config:

    <appSettings>
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    </appSettings>
    
like image 105
SLaks Avatar answered Oct 09 '22 06:10

SLaks


MVC2 provided the choice between Microsoft's own client-side validation, or jQuery validation.

MVC3 continues this, but only provides unobtrusive validation (i.e. new HTML5 validation features) if you go down the jQuery route.

In both cases, the prevailing opinion seems to be that jQuery is the better choice, as it is more easily extended and simpler to use. There is no need to include both scripts in either your project or your webpage - typically, you would choose one and delete the other.

like image 45
Stelloy Avatar answered Oct 09 '22 05:10

Stelloy