简体   繁体   English

部分视图中不显眼的客户端验证无法正常工作

[英]Unobtrusive client side validation in partial view not working

I have read most of the posts on here relating to this issue and I still can't see what's wrong. 我已经阅读了有关此问题的大部分帖子,我仍然看不出有什么问题。 Can someone have a looksy please? 有人可以请一脸吗? I am getting an error "Cannot read property 'unobtrusive' of undefined" If I comment out that line then I get "cannot read property 'options' of undefined" So obviously I have something referenced improperly but I can't see it. 我收到一个错误“无法读取属性'不显眼的'未定义”如果我注释掉该行然后我得到“无法读取未定义的属性'选项”所以很明显我有一些引用不当但我看不到它。 If I take all the validation code out the form pops up and works fine, but of course no validation. 如果我拿出所有的验证代码弹出窗体并且工作正常,但当然没有验证。 Also, I've tried putting "#updateContactForm" in place of "#updateDialog" and got the same results. 另外,我尝试用“#updateContactForm”代替“#updateDialog”并得到相同的结果。 Hoping this is something simple that I just can't see from looking at it for too long. 希望这是一件简单的事情,我从长时间的观察中看不出来。 Thanks in advance! 提前致谢!

    <div id="updateDialog" title="Update Contact"></div>
    <script type="text/javascript">
     var linkObj;
$(function () {
    $(".editLink").button();

    $("#updateDialog").dialog({
        autoOpen: false,
        width: 400,
        resizable: false,
        modal: true,
        buttons: {
            "Update": function () {
                $("#update-message").html(''); //make sure there is nothing on the message before we continue                         
                $("#updateContactForm").submit();
            },
            "Cancel": function () {
                $(this).dialog("close");
            }
        }
    });

            $(".editLink").click(function () {
        //change the title of the dialog
        linkObj = $(this);
        var dialogDiv = $("#updateDialog");
        var viewUrl = linkObj.attr('href');
        $.get(viewUrl, function (data) {
            dialogDiv.html(data);
            //validation
            var $form = $("#updateContactForm");
            $form.unbind();
            $form.data("validator", null);
            $.validator.unobtrusive.parse($("#updateDialog"));
            // Re add validation with changes
            $form.validate($form.data("unobtrusiveValidation").options);
            //open dialog
            dialogDiv.dialog("open");
        });
        return false;
    });

Just to check, have you correctly referenced the jquery validation scripts in the cshtml or master page?. 只是检查一下,您是否正确引用了cshtml或母版页中的jquery验证脚本?

You should load first the script jquery.validate.js and then the jquery.validate.unobtrusive.js one. 您应首先加载脚本jquery.validate.js ,然后jquery.validate.unobtrusive.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM