{"id":6161,"date":"2014-04-13T04:35:53","date_gmt":"2014-04-13T04:35:53","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/client-side-validation-in-mvc-4-with-jquery-1-10-2-collection-of-common-programming-errors-2\/"},"modified":"2014-04-13T04:35:53","modified_gmt":"2014-04-13T04:35:53","slug":"client-side-validation-in-mvc-4-with-jquery-1-10-2-collection-of-common-programming-errors-2","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/13\/client-side-validation-in-mvc-4-with-jquery-1-10-2-collection-of-common-programming-errors-2\/","title":{"rendered":"Client side validation in MVC 4 with jQuery 1.10.2-Collection of common programming errors"},"content":{"rendered":"<p>I am building an <code>ASP.NET MVC 4<\/code> based application and try to follow the code from the standard internet template where&#8217;s possible.<\/p>\n<p>Yesterday I started to implement my forms and noticed that I don&#8217;t get a client side validation and the content is always submitted.<\/p>\n<p>I render the form like this:<\/p>\n<pre><code>@using (Html.BeginForm(new { ReturnUrl = ViewBag.ReturnUrl }))\n{\n    @Html.AntiForgeryToken()\n    @Html.ValidationSummary(true)\n\n        <\/code><\/pre>\n<ul>\n<li><code>@Html.LabelFor(m =&gt; m.Title)<br \/>\n@Html.TextBoxFor(m =&gt; m.Title)<br \/>\n@Html.ValidationMessageFor(m =&gt; m.Title)<\/code><\/li>\n<li><code>\/\/more list items here<\/code>\n<p>and because I didn&#8217;t start with the debugging I render the scripts as follows:<\/p>\n<pre><code>@Scripts.Render(\"~\/Scripts\/jquery-1.10.2.min.js\")\n@Scripts.Render(\"~\/Scripts\/jquery.validate.min.js\")\n@Scripts.Render(\"~\/Scripts\/jquery.unobtrusive-ajax.min.js\")\n@Scripts.Render(\"~\/Scripts\/jquery.validate.unobtrusive.min.js\")\n<\/code><\/pre>\n<p>Then, in firebug, when I submit an incorrect form I get the following error:<\/p>\n<pre><code>TypeError: a(...).live is not a function\n<\/code><\/pre>\n<p>And then I saw this &#8211; <code>Also bear in mind that in jQuery 1.9 the .live() method has been removed which was one of the breaking changes<\/code> an another SO question here. So I decided to try and changed the jQuery version to :<\/p>\n<pre><code>@Scripts.Render(\"~\/Scripts\/jquery-1.7.1.min.js\")\n<\/code><\/pre>\n<p>and the validation started to work normally.<\/p>\n<p>Some further research showed me that most some people made their custom <code>jQuery.val*<\/code> scripts in order to make it work with a new version of <code>jQuery<\/code>.<\/p>\n<p>My question is &#8211; is there a standard packaged\/bundle for client side validation that I can add to my project and use with newer version of <code>jQuery<\/code> (the one I&#8217;m using now is 1.10.2)? Do I have to use <code>jQuery 1.7.*<\/code> for my client validation parts or now there is something else supported by <code>MS<\/code> (like validation using <code>knockout.js<\/code> which is part of the standard template) or maybe even other js library that is now used for client side validation in MVC projects?<\/p>\n<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I am building an ASP.NET MVC 4 based application and try to follow the code from the standard internet template where&#8217;s possible. Yesterday I started to implement my forms and noticed that I don&#8217;t get a client side validation and the content is always submitted. I render the form like this: @using (Html.BeginForm(new { ReturnUrl [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-6161","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=6161"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/6161\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=6161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=6161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=6161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}