- Validation helpers uses jQuery validation plugin for client side validations
- By default, Client Side validation is enabled
Separation of functionality (the “behaviour layer”) from a Web page’s structure/content and presentation
These are Ajax helper methods available in ASP.NET MVC:
Above helper methods in ASP.NET MVC 2 & earlier versions uses Microsoft Ajax Libraries (MicrosoftAjax.js, MicrosoftMvcAjax.js) for generating script & performing operations.
These are Validation helper methods available in ASP.NET MVC:
Validation helpers in ASP.NET MVC 2 & earlier versions uses Microsoft Validation Library (MicrosoftMvcValidation.js) for generating required validation script for client.
For example if we observe this code snippet in view:
Corresponding generated html mark up :
So Microsoft Ajax Libraries attaches event listener to an element in DOM using inline java script.
In ASP.NET MVC 2 & earlier versions client side validation is disabled by default, we can enable validation in any view using <%Html.EnableClientValidation();%> . For example if we observe this code snippet in view corresponding to validation helpers, this code is from LogOn.aspx provided in default ASP.NET MVC 2 project template.
Below the Html.BeginForm() tag we are using <%: Html.ValidationSummary() %> ( Html.ValidationSummary() – Returns an unordered list of validation messages that are in the ModelStateDictionary object) , for at every element we are using <%: Html.ValidationMessageFor() %> for displaying corresponding validation error message.
We can override this settings in global.asax also using HtmlHelper class:
- HtmlHelper.ClientValidationEnabled = false;
To support these new options HtmlHelper class provides following new overloaded methods:
- public void EnableClientValidation(); // available in ASP.NET MVC2
- public void EnableClientValidation(bool enabled)