5

I load list of data by using ajax and partial view(ascx) But I have a problem: my response is cached. I try to write Responce.Cache.SetExpires(DateTime.Now.AddDays(-1)) in ascx file but it is not helped

In ASP.NET WebForms I've solved this by writing Responce.Cache.SetExpires(DateTime.Now.AddDays(-1)) in codebehind. So I'd like to know where can I write Responce.Cache.SetExpires(DateTime.Now.AddDays(-1)) to disable cache.

2
  • it shouldn't be cached unless you explicitly tell it so on the controller action directive. maybe it's the browser? i have heard of ie caching ajax gets (but not posts). Commented Nov 1, 2010 at 8:36
  • yes page is cached by browser. But it is easy to solve by using SetExpires. How can I set SetExpires with MVC? Commented Nov 1, 2010 at 9:17

2 Answers 2

12

Use jQuery?

$.ajax({
 cache:false,
 ...
});

or Controller / Action set OutputCacheAttribute.

OutputCacheAttribute Class (System.Web.Mvc)

Sign up to request clarification or add additional context in comments.

3 Comments

How exactly OutputCacheAttribute will help to disable cache??
This attribute control http response header(cache-control,expires etc).
I meant it would be good here to give an code example how to use OutputCacheAttribute for that: [OutputCache(NoStore = true, Duration = 0, VaryByParam = "*")]
0

You should be using ajax POST to controller method that returns JsonResult if you want to load data from server asynchronously.

2 Comments

If you are getting data, you should not be using POST. Look on HTTP methods as CRUD: Post = Create, Get = Read, Put = Update, Delete = Delete
Arve's comment is not correct. ASP.Net MVC doesn't support REST operations, and it is quite acceptable to use a POST method to retrieve data based on a parameter.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.