0

Is there anyway to disable cache on a action of a returned view? By using an attribute or something? The reason for this is that IE9 and below seem to always cache my views/partial views, so I'd like to prevent that for some actions

2
  • Do you mean browser cache or server cache? Commented Jan 20, 2012 at 13:16
  • Both! I think i've done it with browser cache using JQuery, but Server cache is what I want to disable Commented Jan 20, 2012 at 14:23

1 Answer 1

4

Putting this attribute on an action should do the trick:

[System.Web.Mvc.OutputCache(NoStore = true, Duration = 0)]
Sign up to request clarification or add additional context in comments.

7 Comments

It tells me that duration must be a positive number, so should I just set it to 1? Cache of 1 second should be fine i think?
+1 I edited the post, NoStore instead of VaryByParam. Hope you don't mind.
@BiffBaffBoff: 0 means that no cache should be used.
@jgauffin Not all! I've used [OutputCache(Duration=0, VaryByParam="None"] in the past and it worked for me, but after reading the MSDN docs, your solution actually makes more sense.
This doesnt work: System.InvalidOperationException: Duration must be a positive number. So I've set Duration = 1, 1 second shouldnt cause any harm
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.