Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OutputCache in Razor view engine .cshtml page

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?

like image 312
ram Avatar asked Dec 11 '10 06:12

ram


2 Answers

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).

like image 188
RPM1984 Avatar answered Sep 19 '22 07:09

RPM1984


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.

like image 33
Darin Dimitrov Avatar answered Sep 19 '22 07:09

Darin Dimitrov