MVC3 - AJAX局部视图被缓存...我不能阻止它 [英] MVC3 - AJAX Partial View is being cached...and I can't stop it

查看:192
本文介绍了MVC3 - AJAX局部视图被缓存...我不能阻止它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MVC3 - 我有使用jQuery获得一个javascript函数()来获取来自控制器的PartialView。

I'm using MVC3 - i have a javascript function that uses jQuery get() to get a PartialView from a controller.

问题是,它被缓存和我不断收到内容过时了。

The problem is that it's being cached and i keep getting stale content back.

我试过[的OutputCache(持续时间= 0)]的动作,以为它会prevent它的缓存,但没有喜悦。难道是客户端缓存它吗?

I've tried [OutputCache(Duration=0)] on the action, thinking it would prevent it caching, but no joy. Could it be the client caching it too?

编辑:

我最近一直在用另一种方式来prevent缓存这可能是一些有用的。

I've recently been using another way to prevent caching which may be useful to some.

$.get("/someurl?_="+$.now(),function(data) {  
     // process data
});

这显然不是干净,但因为每个请求通过一个 _ = 12345678 (时间戳)它从未缓存。

It's obviously not as clean, but because each request passes a _=12345678 (timestamp) it's never cached.

希望它帮助。

推荐答案

GET请求可以被浏览器自动缓存,所以你可以使用的 阿贾克斯() 功能,违反了 获得() 功能允许您禁用缓存:

GET requests could be automatically cached by the browser so you could use the .ajax() function which contrary to the .get() function allows you to disabled caching:

$.ajax({
    url: '/foo',
    type: 'GET',
    cache: 'false',
    success: function(result) {

    }
});

另一种可能性是使用POST:

Another possibility is to use POST:

$.post('/foo', function(result) {

});

这篇关于MVC3 - AJAX局部视图被缓存...我不能阻止它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆