jquery ui 对话框在表单加载时缓存
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以将其添加到全局 js 代码中以防止 IE 缓存 ajax 请求:
You can add this to your global js code to prevent IE from ever caching ajax request:
您可以将: 替换
为:
You could replace:
with:
添加属性
[无缓存]
通过您的控制器操作来解决此问题。这种情况只发生在 IE 中
Add the attribute
[NoCache]
To your controller action to fix this issue. This happens only in IE
将随机参数或时间戳附加到要加载的 URL。例如:
Append a random parameter, or timestamp, to the URL to load. For example: