The jQuery UI dialog box will not close


Given the following script:

$(function () {

        autoOpen: false,
        width: 800,
        resizable: false,
        title: 'Edit Person',
        modal: true,
        buttons: {
            "Save": function () {
            "Close": function () {
        close: function (event, ui) {

    $(".editLink").click(function () {
        var dialogDiv = $('#editPersonDialog');
        var linkObj = $(this);
        var viewUrl = linkObj.attr('href');
        $.get(viewUrl, function (data) {
            var $form = $("#updatePersonForm");
            // unbind existing validation
            $"validator", null);
            // check document for changes
            // re-add validation with changes
            // open dialog

        return false;

function updateSuccess() {
    if ($("#update-message").html() == "True") {
        $("#commonMessage").html("Update Complete");
    else {

If I click the "X" button on the dialog the form closes fine. If I click the "Close" button then it does not close. I have verified that the code for the "Close" button is being called.

Both the "X" button and the "Close" button are both running the same statement: '$(this).dialog('close');'. Why would one work and the other not work?

As an aside the dialog will not open a second time unless I refresh the page. I imagine that these 2 problems may be related.

I have found many people with similar problems and a number of different solutions that worked for them. Unfortunately none of them worked for me.

Further Info:

The dialog displays a partial view in an Ajax form:

@using (Ajax.BeginForm("Edit", "Person", null,
    new AjaxOptions
        UpdateTargetId = "update-message",
        InsertionMode = InsertionMode.Replace,
        HttpMethod = "POST",
        OnSuccess = "updateSuccess"
    new { @id = "updatePersonForm" }))
    <div id="update-message"  class="hiddenDiv"></div>
    <div class="blockGraygradient">
        @Html.HiddenFor(model => model.SelectedPerson.Id)
        @Html.HiddenFor(model => model.SelectedPerson.RowVersion)
        @Html.HiddenFor(model => model.SelectedPerson.CreateTime)

Try using this instead.


We had exactly the same problem. In the end, every time you re-opened the dialog it was actually re-injecting the dialog markup into the DOM. Then, when you click close (for the second time) it only closes the first occurrence of the dialog, but not necessarily the one that's open. You can check this using a run-time DOM inspector like FireBug or Chrome's built-in developer tools.