30

I am trying to use the jQueryUI dialog in an MVC3 application but having an issue with it. The dialog I have is loading a partial view into it where the user will either edit or create a new item. This works fine but if I try to save or update the item, or if I try to close it I get the message in the title.

I have added all of the required .js files but still getting the error. I have also used firebug but still can't find why error is happening.

HTML

<span class="EditLink ButtonLink" addressId="@addr.Id">Modify this Address</span>
<div id="popup"></div>

JavaScript

$(document).ready(function () {
    var id = 0;

    //define config object
    var dialogOpts = {
        title: "Edit item",
        modal: true,
        autoOpen: false,
        height: 500,
        width: 500,
        open: function () {
            $("#popup").load("/partialviewtoload/" + id);
        },
        buttons: {
            Cancel: function() {
                $(this).dialog('close');
            }
        }
    };

    $("#popup").dialog(dialogOpts);    //end dialog

    $('.EditLink').click(function() {
        id = $(this).attr("itemId");
        $("#popup").dialog("open");
        return false;
    });    
});
0

3 Answers 3

61

issue was that I was referencing "jquery-1.5.1.min.js" twice. Once in the _Layout.cshtml and also in the partial view I was loading. . Removed the reference in the partial view and got it sorted.

Sign up to request clarification or add additional context in comments.

Comments

5

It seems that browser have not loaded jQueryUI, ensure that it is in your DOM

4 Comments

It has loaded jqueryui as I can see it using firebug. Also, the dialog loads the first time no problem. The issue is trying to close it using the $(this).dialog('close') and also reopening it.
So, I think that $(this) is not pointing to an element containing dialog object. Before $(this).dialog('close') test $(this) by console.log(this)
OK, the console shows the div "popup". but straight after that i get the error again.
I have narrowed the cause of the issue. It only happens when I load the partial view into the dialog. If I don't load the partial view I can close and reopen no problem.
0

In my case it was that

you should include first grid.locale-en.js and then jquery.jqGrid.min.js.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.