Search code examples
asp.net-mvc-3client-side-validation

ASP.MVC3 is client side validation enabled by default?


In my Layout page, i have the following links to the validation Javascript files,

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

My entities are decorated with validation attributes like

[Required(ErrorMessage ="Please enter a customer name")]
    public string CustomerName { get; set; }

Then in my view i have validation messages specified after the update fields like so

<div class="label-for">@Html.LabelFor(model => model.CustomerName)</div>
<div class="editor">@Html.EditorFor(model => model.CustomerName)</div>
@Html.ValidationMessageFor(model => model.CustomerName) 

The validation is working however its not on the client side, the way i understand this is that error messages should be displayed when one of the fields is left blank afer tabbing to another field, is there anything else required to get client side validation working?


Solution

  • IIRC there were some incompatibilities between jquery and jquery.validate versions. You seem to be using an old version of jquery 1.4.4. Try updating with the latest. For example install the ASP.NET MVC 3 Tools Update and create a new ASP.NET MVC project in Visual Studio which will get you the proper versions of the following scripts: jquery, jquery.validate and jquery.validate.unobtrusive.