0

我正在打开一个查询对话框,它在 MVC 应用程序中有两个查询选项卡。两个标签加载不同的部分页面。我已经在其中一个选项卡中形成。表单验证工作正常。当表单中没有验证错误时,我收到错误 $element[0] is undefined in jquery.validate.js @ line 806 。我无法理解什么问题。下面是代码:

    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>
        <script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
        <script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>

Partial view which open in one of tab:
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>

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

任何帮助,将不胜感激。这里发生了什么事?

4

1 回答 1

-1

您应该在mySuccess回调中用作OnSuccess处理程序,而不是在. 您不应该在部分中有 document.ready 处理程序。顺便说一句,您不应该在部分内容中有任何 javascript。JavaScript 应该写在单独的文件中。部分视图应该只包含标记。AjaxForm$.validator.unobtrusive.parsedocument.ready

于 2012-07-09T14:06:08.113 回答