简体   繁体   English

关闭后如何在jquery中重新打开模态对话框?

[英]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. 我有一个Asp.Net MVC应用程序,在1 View中,我有一个列表,每个记录显示Edit图标。 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 : 以下是我打开对话框的jquery代码:

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;
        });
});
    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" ); 如果$( this ).dialog( "close" ); not working because not try this specific sentence?? 不工作,因为没有尝试这个特定的句子?

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

The above issue can be solved by including the below scripts in parent view from where the dialog popup is clicked & initiated : 上述问题可以通过在父视图中包含以下脚本来解决,其中单击并启动对话框弹出窗口:

<script type="text/javascript" src="../../Scripts/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.validate.min.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.validate.unobtrusive.min.js"></script>

As well as insert the below scripts in child view which is the UI for modal dialog popup : 以及在子视图中插入以下脚本,子视图是模式对话框弹出窗口的UI:

<script type="text/javascript" src="../../Scripts/jquery.validate.min.js"></script>
<script type="text/javascript" src="../../Scripts/jquery.validate.unobtrusive.min.js"></script>

By scripting in such way, the jquery script conflict is avoided & reopening of dialog can be swiftly done. 通过以这种方式编写脚本,可以避免jquery脚本冲突,并且可以快速完成对话框的重新打开。

你可以使用open方法:

$('#addSingleTimeDialog').dialog('open');

Try writing $( this ).dialog( "close" ); 试着写$( this ).dialog( "close" ); method in close function. 关闭函数的方法。 Eg : 例如:

close: function(){ $( this ).dialog( "close" ); },

$( this ).dialog( "close" ); does not destroy the dialog, instead it just closes and makes it available to be used for next time. 不破坏对话框,而是关闭它并使其可用于下次。

Came across this older question, found a simpler solution not listed here. 遇到这个较旧的问题,发现了一个更简单的解决方案,未列在此处。

Add an event listener for the close event, and call destroy when the dialog is closed. 为close事件添加事件侦听器,并在关闭对话框时调用destroy。

close: function(event, ui) {$(this).dialog("destroy");}

My problem was solved by replacing 我的问题通过更换解决了

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

with

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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