asp.net mvc禁用ajax缓存

tak*_*shi 5 ajax asp.net-mvc jquery

我使用ajax和部分视图(ascx)加载数据列表但我有一个问题:我的响应被缓存.我尝试在ascx文件中编写Responce.Cache.SetExpires(DateTime.Now.AddDays(-1))但是没有帮助

在ASP.NET WebForms中,我通过在codebehind中编写Responce.Cache.SetExpires(DateTime.Now.AddDays(-1))来解决这个问题.所以我想知道在哪里可以编写Responce.Cache.SetExpires(DateTime.Now.AddDays(-1))来禁用缓存.

小智 12

使用jQuery?

$.ajax({
 cache:false,
 ...
});
Run Code Online (Sandbox Code Playgroud)

或Controller/Action设置OutputCacheAttribute.

OutputCacheAttribute类(System.Web.Mvc)