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
1 Answer
Putting this attribute on an action should do the trick:
[System.Web.Mvc.OutputCache(NoStore = true, Duration = 0)]
-
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? Commented Jan 20, 2012 at 13:21
-
2+1 I edited the post, NoStore instead of VaryByParam. Hope you don't mind.– jgauffinCommented Jan 20, 2012 at 13:23
-
-
@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. Commented Jan 20, 2012 at 14:04 -
This doesnt work: System.InvalidOperationException: Duration must be a positive number. So I've set Duration = 1, 1 second shouldnt cause any harm Commented Jan 20, 2012 at 14:04