Using ASP.NET MVC web forms we can put output cache either in controller level or view level. How can we mention "outputcache" in .cshtml page?
I did not find it anywhere. Where can I get the syntax?
What do you mean "ASP.NET MVC Web Forms"? If you're referring to the OutputCache
attribute in the Page directive, that is ASP.NET Web Forms.
ASP.NET MVC has Output Caching on the controller action level:
[OutputCache(Duration=10, VaryByParam="none")]
public ActionResult Index()
{
return View();
}
This is irrespective of the view engine (ASPX/Razor).
Using ASP.NET MVC web forms you can can put output cache on the view level but this wouldn't have effect. It's there because it's an heritage from classic ASP.NET. In ASP.NET MVC the output cache should always be placed on the controller action.
Because putting cache values in the view makes no sense in the newly introduced Razor view engine there's not such possibility. You should always put this attribute on the controller action.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With