Client side validation in MVC 4 with jQuery 1.10.2-Collection of common programming errors
I am building an ASP.NET MVC 4
based application and try to follow the code from the standard internet template where’s possible.
Yesterday I started to implement my forms and noticed that I don’t get a client side validation and the content is always submitted.
I render the form like this:
@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
@Html.LabelFor(m => m.Title)
@Html.TextBoxFor(m => m.Title)
@Html.ValidationMessageFor(m => m.Title)//more list items here
and because I didn’t start with the debugging I render the scripts as follows:
@Scripts.Render("~/Scripts/jquery-1.10.2.min.js") @Scripts.Render("~/Scripts/jquery.validate.min.js") @Scripts.Render("~/Scripts/jquery.unobtrusive-ajax.min.js") @Scripts.Render("~/Scripts/jquery.validate.unobtrusive.min.js")
Then, in firebug, when I submit an incorrect form I get the following error:
TypeError: a(...).live is not a function
And then I saw this –
Also bear in mind that in jQuery 1.9 the .live() method has been removed which was one of the breaking changes
an another SO question here. So I decided to try and changed the jQuery version to :@Scripts.Render("~/Scripts/jquery-1.7.1.min.js")
and the validation started to work normally.
Some further research showed me that most some people made their custom
jQuery.val*
scripts in order to make it work with a new version ofjQuery
.My question is – is there a standard packaged/bundle for client side validation that I can add to my project and use with newer version of
jQuery
(the one I’m using now is 1.10.2)? Do I have to usejQuery 1.7.*
for my client validation parts or now there is something else supported byMS
(like validation usingknockout.js
which is part of the standard template) or maybe even other js library that is now used for client side validation in MVC projects?