{"id":2864,"date":"2014-03-01T11:26:21","date_gmt":"2014-03-01T11:26:21","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/01\/element-0-is-undefined-on-form-post-in-mvc-collection-of-common-programming-errors\/"},"modified":"2014-03-01T11:26:21","modified_gmt":"2014-03-01T11:26:21","slug":"element-0-is-undefined-on-form-post-in-mvc-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/01\/element-0-is-undefined-on-form-post-in-mvc-collection-of-common-programming-errors\/","title":{"rendered":"element 0 is undefined on form post in MVC-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m opening a query dialog box which has two query tabs in MVC application. both tabs loading different partial pages. I&#8217;ve form in one of tab. form validation works fine. I&#8217;m getting error $element[0] is undefined in jquery.validate.js @ line 806 <strong>when there is no validation error in form<\/strong>. I&#8217;m unable to understand whats issue. below is code:<\/p>\n<pre><code>    Include references in _Layout.cshtml:\n        \n        \n        \n        \n\nPartial view which open in one of tab:\n    \n\n@using (Ajax.BeginForm(\"UpdateMediaCode\", \"MediaCode\", null,\n        new AjaxOptions\n        {\n            UpdateTargetId = \"myMsg\",\n            InsertionMode = InsertionMode.Replace,\n            HttpMethod = \"POST\",\n            OnSuccess = \"mySuccess\"\n        }, new { @id = \"myFormId\" }\n        ))\n{\n    @Html.ValidationSummary(true) \n }\n\n    $(document).ready(function () {\n        $.validator.unobtrusive.parse($('#myFormId));\n    }\n\n<\/code><\/pre>\n<p>any help would be appreciated. what&#8217;s happing here?<\/p>\n<ol>\n<li>\n<p>It is inside the <code>mySuccess<\/code> callback used as <code>OnSuccess<\/code> handler in your <code>AjaxForm<\/code> that you should call <code>$.validator.unobtrusive.parse<\/code> method, not inside a <code>document.ready<\/code>. You shouldn&#8217;t have a document.ready handler inside a partial. You shouldn&#8217;t have any javascript inside a partial by the way. JavaScript should be written in separate files. Partial views should contain only markup.<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m opening a query dialog box which has two query tabs in MVC application. both tabs loading different partial pages. I&#8217;ve form in one of tab. form validation works fine. I&#8217;m getting error $element[0] is undefined in jquery.validate.js @ line 806 when there is no validation error in form. I&#8217;m unable to understand whats issue. [&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-2864","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2864","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=2864"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2864\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}