How to Enable and Disable Client-Side Validation in MVC

How to Enable and Disable Client-Side Validation in MVC

02 Aug 2025
Intermediate
228K Views
4 min read
Learn with an interactive course and practical hands-on labs

ASP.NET MVC with Web API Online Course - Learn & Certify

Client-Side Validation in MVC: An Overview

In this MVC Tutorial, we will see how to enable and disable Client-side validation. MVC3 & MVC4 supports unobtrusive client-side validation in which validation rules are defined using attributes added to the generated HTML elements. These rules are interpreted by the included JavaScript library and use the attribute values to configure the jQuery Validation library which does the actual validation work.

In this article, I would like to demonstrate various ways of enabling or disabling client-side validation.

Read More: MVC Interview Questions and Answers

Enable Client-Side Validation in MVC

For enabling client-side validation, we are required to include the jQuery min, validate & unobtrusive scripts in our view or layout page in the following order.

 <script src="@Url.Content("~/Scripts/jquery-1.6.1.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>

The order of included files, as shown above, is fixed since the below javascript library depends on the top javascript library.

Enabling and Disabling Client-Side Validation at Application Level

We can enable and disable the client-side validation by setting the values of ClientValidationEnabled & UnobtrusiveJavaScriptEnabled keys to true or false. This setting will be applied to the application level.

 <appSettings>
<add key="ClientValidationEnabled" value="true"/>
<add key="UnobtrusiveJavaScriptEnabled" value="true"/>
</appSettings> 

For client-side validation, the values of both keys must be true. When we create a new project using Visual Studio in MVC3 or MVC4, by default the values of both the keys are set to true.

We can also enable the client-side validation programmatically. For this, we need to do code within the Application_Start() event of the Global.asax, as shown below.

 protected void Application_Start() 
{
//Enable or Disable Client Side Validation at Application Level
HtmlHelper.ClientValidationEnabled = true;
HtmlHelper.UnobtrusiveJavaScriptEnabled = true;
}

Enabling and Disabling Client-Side Validation for Specific View

We can also enable or disable client-side validation for a specific view. For this, we are required to enable or disable client-side validation inside a Razor code block as shown below. This option will override the application level settings for that specific view.

 @model MvcApp.Models.Appointment
@{
ViewBag.Title = "Make A Booking";
HtmlHelper.ClientValidationEnabled = false;
}
...
Summary

I hope you will enjoy the tricks while programming with MVC3 & MVC4. I would like to have feedback from my blog readers. Your valuable feedback, questions, or comments about this article are always welcome. Enjoy Coding...!

Unlock the Next Level of MVC

FAQs

By setting the values of ClientValidationEnabled & UnobtrusiveJavaScriptEnabled keys to true or false.

We can use the [ValidateInput(false)] attribute

For this,tell jQuery Unobtrusive Validation to parse the dynamic form immediately after you create it
Share Article
About Author
Shailendra Chauhan (Microsoft MVP, Founder & CEO at ScholarHat)

He is a renowned Speaker, Solution Architect, Mentor, and 10-time Microsoft MVP (2016–2025). With expertise in AI/ML, GenAI, System Design, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development, he bridges traditional frameworks with next-gen innovations.

He has trained 1 Lakh+ professionals across the globe, authored 45+ bestselling eBooks and 1000+ technical articles, and mentored 20+ free courses. As a corporate trainer for leading MNCs like IBM, Cognizant, and Dell, Shailendra continues to deliver world-class learning experiences through technology & AI.
Live Training - Book Free Demo
ASP.NET Core Certification Training
21 Sep
07:00AM - 09:00AM IST
Checkmark Icon
Get Job-Ready
Certification
ASP.NET Core Project
28 Sep
10:00AM - 12:00PM IST
Checkmark Icon
Get Job-Ready
Certification
Accept cookies & close this