Problem in validation

Dec 25, 2013 at 9:49 AM
I am at Part 6: Using Data Annotations for Model Validation for MVC Music store application
server validation is done in model and client side validation is validation built in, requiring no additional work whatsoever. Server side validation is working but client side is not

Somebody please help
Feb 1, 2015 at 2:31 PM
Hi,

I had the same issue and figured out it is because I use Visual Studio 2013 Community. As I first landed on this page and was disappointed not to find a solution, here is mine for those about to "follow" ;-)

It seems that on an empty project (which this tutorial uses) VS2013 doesn't include the needed javascript files for client-side validation (and of course doesn't link them up correctly).

In Detail you need:
  • jquery.validate-vsdoc.js
  • jquery.validate.js
  • jquery.validate.min.js
  • jquery.validate.unobstrusive.js
  • jquery.validate.unobstrusive.min.js
    (not sure if the validate.*.mins wouldn't suffice either)
The easiest way to set it up is by using the Packet-Manager (nuget) -> Tools -> NuGet Packet Manager ->Packet Manager Console and then:
  • Install-Package jQuery.Validation.Unobtrusive.Native.MVC5
  • Install-Package Microsoft.jQuery.Unobtrusive.Validation -Version 3.2.2
Afterwards you should update jquery.validate via -> Tools -> NuGet Packet Manager -> Manage NuGet Packages for Solution. Left Sidebar under Update.
That is because Range Validation is broken in jquery.validate version 10.0.2 (?) which is the one delivered with VS.

Now you just add:
<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
to ~/Views/shared/_Layout.cshtml AFTER the part where JQuery itself is included.

Mind you, this is probably the "quick and dirty" way, because the validation-Scripts are now included in EVERY view.

The way VS2013 does it on a non empty MVC-Solution is by building bundles and rendering validation-Scripts only on Views with an actual input-form. What it does there automatically, would require you to manually alter 4 files plus any view you want to validate and install System.Web.Optimizations via NuGet
Nonetheless I did just that for "fun" and could post that solution if you or anyone else is interested.

Greetings

Daniel