iframe在设置src属性时调用Action方法两次

iframe calls Action method twice while setting src attributes

本文关键字:方法 两次 Action 调用 设置 src 属性 iframe      更新时间:2023-09-26

我正在通过iframe从控制器端调用action方法。SRC属性,它返回部分视图,但调用了两次原因是什么谁能帮我解决这个

在这里找到我的代码

 $('#testdailog').dialog({
        autoOpen: false,
        title: 'Split Fax',
        height: 'auto',
        width: '80%',
        position: ['top', 50],
        draggable: false,
        show: 'blind',
        hide: 'blind',
        modal: true,
        open: function (event, ui) {
            var frameSet = document.getElementById("testdailogFrame");
            frameSet.src='@Url.Action("TestPage", "Fax")';
 },
            close: function (event, ui) {
                var frameSet = document.getElementById("testdailogFrame");
                frameSet.src="about:blank";
        });

通过更改iframe内容更改的代码而不是SRC属性

解决了这个问题
 $('#testdailog').dialog({
        autoOpen: false,
        title: 'Split Fax',
        height: 'auto',
        width: '80%',
        position: ['top', 50],
        draggable: false,
        show: 'blind',
        hide: 'blind',
        modal: true,
        open: function (event, ui) {
 $.ajax({
                    url: '@Url.Action("TestPage","Fax")',
                    type: 'GET',    
                    cache:false,
                    success: function(data){
                        var frameSet = document.getElementById("testdailogFrame");
                        var iframedoc = frameSet.document;
                        if (frameSet.contentDocument)
                            iframedoc = frameSet.contentDocument;
                        else if (frameSet.contentWindow)
                            iframedoc = frameSet.contentWindow.document;
                        if (iframedoc){
                            iframedoc.open();
                            iframedoc.writeln(data);
                            iframedoc.close();
                        }
                    },
                    error: function () {
                        window.location.href = '@Url.Action("Index","Error")';
                    }
                });
            },
}
});