简体   繁体   中英

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. 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?.

You should load first the script jquery.validate.js and then the jquery.validate.unobtrusive.js one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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