4

I a partial page creating the menu for application. I am calling the menu partial view using renderaction. I want to store this partial page on client side by doing this

[OutputCache(Duration=7200, Location  =OutputCacheLocation.Client, NoStore= true)]

but i am getting the following error

OutputCacheAttribute for child actions only supports Duration, VaryByCustom, and VaryByParam values. Please do not set CacheProfile, Location, NoStore, SqlDependency, VaryByContentEncoding, or VaryByHeader values for child actions

Any alternate to this

Tassadaque
  • 8,129
  • 13
  • 57
  • 89

1 Answers1

2

Client side caching is not possible for partials in MVC 3. The client browser just receives HTML, 'partials' only exist on the server side.

Why don't you use server side caching?

When the content of your menu is dependent on the user, you could add the relevant user information to the parameters of your child action. For example:

[OutputCache(Duration=7200, VaryByParam="*")]  
public PartialViewResult Menu(int userId)
{
   ...
}
Chaim Zonnenberg
  • 1,793
  • 13
  • 10
  • 1
    Wouldn't that take too much memory on the server ? This will produce as many instances as active user's within 2 hour range. And not sure but i suppose this will store actual html on memory not just some variables so space will be much bigger . – Anestis Kivranoglou Jan 28 '14 at 17:46
  • This isn't a practical solution. You might want to show a welcome message along with the user name at the top of every page. And even if your could add a parameter designating the user, saving output for thousands of users in the memory is not a smart move to say the least. – SepehrM Jun 15 '16 at 07:07