core
core

Reputation: 33059

Disabling caching for MVC Controller Action

I know I can write a custom ActionFilter for an ASP.NET MVC Controller Action to set headers in the response that will disable caching.

My question is, is there an out-of-the-box ActionFilter in the MVC BCL that already does this? Or must I have to create my own custom one?

Upvotes: 1

Views: 164

Answers (1)

haim770
haim770

Reputation: 49095

You can use the [OutputCache] filter:

[HttpGet]
[OutputCache(Location = OutputCacheLocation.None, NoStore = true)]
public ActionResult Index()
{
      // ....
      return View();
}

See MSDN

Upvotes: 1

Related Questions