Shalin Jirawla Shalin Jirawla - 5 months ago 24
jQuery Question

how to reopen modal dialog in jquery after closing it?

I have an Asp.Net MVC application, where in 1 View, I have a list with every record showing Edit icon. Clicking the edit icon opens a modal dialog popup to update the record .

I face problem in reopening the dialog or clicking other edit icon for popup after closing the dialog .
Following is my jquery code to open the dialog :

var singltym;

$(function () {

$('#addSingleTimeDialog').dialog({
cache: false,
autoOpen: false,
width: 450,
height: 450,
closeOnEscape: true,
resizable: true,
modal: true});

$('#singletymlink').on('click', function () {
singltym = $(this);
var dialogDiv = $('#addSingleTimeDialog');
var viewUrl = singltym.attr('href');
$.ajax({
cache: false,
url: viewUrl,
dataType: 'html',
success: function (data) {
dialogDiv.html(data);
dialogDiv.dialog('open');
}
});
return false;
});
});

Answer
    var singltym;

    $(function () {

        $('#addSingleTimeDialog').dialog({
                cache: false,
                autoOpen: false,
                width: 450,
                height: 450,
                closeOnEscape: true,
                resizable: true,
                modal: true});

        $('#singletymlink').on('click', function () {
                singltym = $(this);
                var dialogDiv = $('#addSingleTimeDialog');
                var viewUrl = singltym.attr('href');
                $.ajax({
                    cache: false,
                    url: viewUrl,
                    dataType: 'html',
                    success: function (data) {
                        dialogDiv.html(data);
                       dialogDiv.dialog('open');

//I work in this method

                  $( this ).dialog( "close" );

                }
            });
        });
});

Or

$.ajax({
                    cache: false,
                    url: viewUrl,
                    dataType: 'html',
                    success: function (data) {
                        dialogDiv.html(data);
                       $("#dialogDiv").dialog("open");

                  $( this ).dialog( "close" );

                }

If $( this ).dialog( "close" ); not working because not try this specific sentence??

$('#addSingleTimeDialog').dialog("close");