Take the 2-minute tour ×

I'm opening a query dialog box which has two query tabs in MVC application. both tabs loading different partial pages. I've form in one of tab. form validation works fine. I'm getting error $element[0] is undefined in jquery.validate.js @ line 806 when there is no validation error in form. I'm unable to understand whats issue. below is code:

    Include references in _Layout.cshtml:
        <script src="@Url.Content("~/Scripts/jquery-1.7.2.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/jquery-ui-1.8.20.min.js")" type="text/javascript"></script>

Partial view which open in one of tab:

@using (Ajax.BeginForm("UpdateMediaCode", "MediaCode", null,
        new AjaxOptions
            UpdateTargetId = "myMsg",
            InsertionMode = InsertionMode.Replace,
            HttpMethod = "POST",
            OnSuccess = "mySuccess"
        }, new { @id = "myFormId" }
<script type="text/javascript">
    $(document).ready(function () {

any help would be appreciated. what's happing here?

share|improve this question

1 Answer 1

It is inside the mySuccess callback used as OnSuccess handler in your AjaxForm that you should call $.validator.unobtrusive.parse method, not inside a document.ready. You shouldn't have a document.ready handler inside a partial. You shouldn't have any javascript inside a partial by the way. JavaScript should be written in separate files. Partial views should contain only markup.

share|improve this answer
am still getting error even after moving $.validator.unobtrusive.parse to onSuccess. BTW, am getting error even this line is commented –  user1480864 Jul 9 '12 at 14:25
I suppose that's because you have included the jquery.validate.unobtrusive.js script after the jquery and jquery.validate script which obviously is wrong. Your scripts should be included in the correct order which is: 1. jquery, 2. jquery.validate, 3. jquery.validate.unobtrusive. Don't include scripts in your partial views. –  Darin Dimitrov Jul 9 '12 at 14:27
am not expert in Jquery. not sure, whats happoing. I changed script order and removed jquery.validate. My main page started throwing errors. and if I don't exclude jquery.validate.unobtrusive from partial view, it doesn't perform validation. –  user1480864 Jul 9 '12 at 14:48
You should not remove jquery.validate. The jquery.validate.unobtrusive script depends on jquery.validate. –  Darin Dimitrov Jul 9 '12 at 14:49
"element 0 is undefined " error still persits –  user1480864 Jul 9 '12 at 14:54

Your Answer


