asp.net mvc client side validation not working? asp.net mvc client side validation not working? asp.net asp.net

asp.net mvc client side validation not working?


For some reason the Html helpers does not have generated validation attributes in the inputs (data-val="true" and the others), check that. Besides to check the order in which the javascript libraries are loaded:

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


Your problem is likely that you have jQuery at the bottom of your file, but you are putting jquery.validate at the top. jQuery has to come before jQuery.validate. I would suggest always putting jQuery in your header, not in the body, and it should be the first thing after modernizr.

Also, you do know that jQuery 2.x does not work with IE8 ore earlier, right?


It seems that your jquery.validate.js is in wrong position. It must be after main jquery ref.

For MVC 5, it should be as following:

_Layout.cshtml: (bottom of page)

<body>......@Scripts.Render("~/bundles/jquery")@Scripts.Render("~/bundles/bootstrap")@Scripts.Render("~/bundles/jqueryval") <!-- *required for client side validation! -->@RenderSection("scripts", required: false)</body>

where ~/bundles/jqueryval is defined in BundleConfig.cs: RegisterBundles() method:

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