0

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;
    });
abatishchev
  • 98,240
  • 88
  • 296
  • 433
KMW_Denver
  • 57
  • 1
  • 8
  • may b you should read this question
    http://stackoverflow.com/questions/5965470/client-side-validation-with-dynamically-added-field
    – Parv Sharma May 30 '12 at 05:51

1 Answers1

2

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.

eddo
  • 2,094
  • 1
  • 25
  • 31