To ensure that JQuery isn't caching the results, on your ajax methods, put the following:
//rest of your ajax setup
Or to prevent caching in MVC, we created our own attribute, you could do the same. Here's our code:
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Method)]
public sealed class NoCacheAttribute : ActionFilterAttribute
public override void OnResultExecuting(ResultExecutingContext filterContext)
Then just decorate your controller with [NoCache]. OR to do it for all you could just put the attribute on the class of the base class that you inherit your controllers from (if you have one) like we have here:
public class ControllerBase : Controller, IControllerBase
You can also decorate some of the actions with this attribute if you need them to be non-cacheable, instead of decorating the whole controller.
If your class or action didn't have NoCache when it was rendered in your browser and you want to check it's working, remember that after compiling the changes you need to do a "hard refresh" (Ctrl+F5) in your browser. Until you do so, your browser will keep the old cached version, and won't refresh it with a "normal refresh" (F5).
I tried everything in the above solution and it does not work for me.
and a +1 to the editor @JotaBe of this answer.
It's my understanding (and I'm no jQuery expert) that cache:false only makes jQuery tack on to the query string a changing value to "trick" the browser into thinking the request is for something else. In theory, this means the browser would still cache the results, just wouldn't use the cached results. Should be more efficient on the client to disable caching via response headers.
Worked only on controller level and not on action level.
Thank you for your answer. I just ran into this issue with IE and MVC 5, using Angular 1.2.16. Chrome didn't have this issue at all, but the overall fix is to create your attribute. Works great now.
I would upvote including such an attribute in the official ASP.NET package :-)
@Frdric, the section of the spec you point to says that caches cannot cache no-store content: The "no-store" response directive indicates that a cache MUST NOT store any part of either the immediate request or response.