Client-side validation not working in ASP.NET MVC5 with Bootstrap Client-side validation not working in ASP.NET MVC5 with Bootstrap asp.net asp.net

Client-side validation not working in ASP.NET MVC5 with Bootstrap


I had the same problem. Comparing the generated HTML with a site that worked, I noticed that at the end of the document, there was this:

<script src="/bundles/jqueryval"></script>

...whereas the bundle should have been expanded like this:

<script src="/Scripts/jquery.validate.js"></script><script src="/Scripts/jquery.validate.unobtrusive.js"></script>

I looked in App_Start/BundleConfig.cs, and sure enough, the JQuery validation bundle had not been defined in RegisterBundles. I had to add:

bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(                    "~/Scripts/jquery.validate*"));

Why this was missing, I don't know. I started with a new, clean project.

It's pretty shoddy that there's no compile-time error when you reference an undefined bundle. Even an always-on run-time error would be better than silent failure. So much time wasted!

EDIT: turns out I didn't have the JQuery validation scripts in my project, either. I had to add them via NuGet ("Microsoft JQuery Unobtrusive Validation").


I was having same problem. The solution is to add .js reference to master page (_Layout.cshtml)

  1. jquery.validate.js
  2. jquery.validate.unobtrusive.js


Have you verified <add key="ClientValidationEnabled" value="true" /> in web.config?

Otherwise, this provides a good overview: ASP.NET MVC 3: Required steps for unobtrusive client-side validation of dynamic/AJAX content. Also valid for MVC5.