jquery ui 对话框在表单加载时缓存

发布于 2024-12-15 16:33:59 字数 1629 浏览 3 评论 0原文

使用 ASP.NET MVC3 (Razor),我有一个加载 jQuery UI 对话框的简单页面。

@{
    ViewBag.Title = "Home Page";
}
<h2>yo</h2>
<div id="fileUpload">
</div>
<button id="button2">
    Upload file
</button>
<script type="text/javascript">
    $(document).ready(function () {
        $('#button2').click(function () {
            $fileUpload = $('#fileUpload');
            $fileUpload.dialog({
                minWidth: 500,
                minHeight: 100,
                title: 'Upload File(s)',
                autoOpen: true,
                buttons: {
                    'Upload': function () {
                        $('form').submit();
                    },
                    'Cancel': function () {
                        $(this).dialog('close');
                    }
                },
                open: function (event, ui) {
                    $(this).load('@Url.Action(MVC.FileUpload.FileUpload())');
                },
                close: function (event, ui) {
                    $(this).dialog('destroy');
                    //$(this).remove();
                },
                dialogClass: 'no-close',
                closeText: '',
                modal: true
            });
        });
    });
</script>

注意 open() 表单调用了控制器方法。它返回一个 PartialView ,看起来像这样......

public virtual ActionResult FileUpload() { return new 部分视图结果(); }

是 IE 正在缓存对部分视图的调用。如果我更新部分视图,那么在清除浏览器缓存之前它不会加载。

我已经尝试过 close() 和 .remove() 上的“销毁”方法。两者都没有效果。我还确认每次单击 #button2 时都会调用 open() 。

关于如何防止对话框内容被缓存有什么想法吗?

With ASP.NET MVC3 (Razor) I have a simple page that loads a jQuery UI dialog.

@{
    ViewBag.Title = "Home Page";
}
<h2>yo</h2>
<div id="fileUpload">
</div>
<button id="button2">
    Upload file
</button>
<script type="text/javascript">
    $(document).ready(function () {
        $('#button2').click(function () {
            $fileUpload = $('#fileUpload');
            $fileUpload.dialog({
                minWidth: 500,
                minHeight: 100,
                title: 'Upload File(s)',
                autoOpen: true,
                buttons: {
                    'Upload': function () {
                        $('form').submit();
                    },
                    'Cancel': function () {
                        $(this).dialog('close');
                    }
                },
                open: function (event, ui) {
                    $(this).load('@Url.Action(MVC.FileUpload.FileUpload())');
                },
                close: function (event, ui) {
                    $(this).dialog('destroy');
                    //$(this).remove();
                },
                dialogClass: 'no-close',
                closeText: '',
                modal: true
            });
        });
    });
</script>

Notice on open() the form makes a call to a controller method. It returns a PartialView and looks like this...

public virtual ActionResult FileUpload() { return new
PartialViewResult(); }

The problem I am having is IE is caching the call to the partial view. If I update the partial view then it does not load until I clear the browser cache.

I have tried the 'destroy' method on close() as well as .remove(). Neither have an effect. I have also confirmed open() is called each time #button2 is clicked.

Any ideas on how to keep the dialog contents from getting cached?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你对谁都笑 2024-12-22 16:33:59

您可以将其添加到全局 js 代码中以防止 IE 缓存 ajax 请求:

$.ajaxSetup({ cache: false });

You can add this to your global js code to prevent IE from ever caching ajax request:

$.ajaxSetup({ cache: false });
月隐月明月朦胧 2024-12-22 16:33:59

您可以将: 替换

 $(this).load('@Url.Action(MVC.FileUpload.FileUpload())');

为:

$.ajax({
    url: '@Url.Action(MVC.FileUpload.FileUpload())',
    cache: false,
    context: this,
    success: function(result) {
        $(this).html(result);
    }
});

You could replace:

 $(this).load('@Url.Action(MVC.FileUpload.FileUpload())');

with:

$.ajax({
    url: '@Url.Action(MVC.FileUpload.FileUpload())',
    cache: false,
    context: this,
    success: function(result) {
        $(this).html(result);
    }
});
蓝眼睛不忧郁 2024-12-22 16:33:59

添加属性
[无缓存]
通过您的控制器操作来解决此问题。这种情况只发生在 IE 中

Add the attribute
[NoCache]
To your controller action to fix this issue. This happens only in IE

青丝拂面 2024-12-22 16:33:59

将随机参数或时间戳附加到要加载的 URL。例如:

var timestamp = new Date().getTime();
$(this).load('@Url.Action(MVC.FileUpload.FileUpload())'+'&t='+timestamp);

Append a random parameter, or timestamp, to the URL to load. For example:

var timestamp = new Date().getTime();
$(this).load('@Url.Action(MVC.FileUpload.FileUpload())'+'&t='+timestamp);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文