views:

918

answers:

3

I have a ViewPage that contains <% Html.RenderAction<MyController>(c => c.SidebarStats()); %>. On the controller action for the action SidebarStats I have an OutputCache action filter to cache only that part of the page. However, the whole page is getting cached and not just that action.

I remember seeing somewhere that this might be a bug with ASP.NET MVC though I'm not sure. I'm currently using ASP.NET MVC RC1, IIS7, Windows Server 2008 and .NET 3.5 SP1.

+2  A: 

According to Microsoft this is a known bug with no known fix. Only workarounds suggested are to create your own OutputCache action filter.

Chad Moran
+7  A: 

I blogged a solution to this problem here. It's simple, but it only works if you're using the WebFormViewEngine. We will look hard into figuring out what it will take to make this work for all view engines.

Haacked
You the man Phil, I knew there had to be an elegant solution. Thanks!
Chad Moran
Is this bug fixed in V2?
CVertex
@CVertex no. Is this will be fixed in V3, working with Razor view engine?
stacker
A: 

You can make caching to the data but not to the view. I know you don't want that but it may be useful :

public PartialViewResult GetSiteParts(string Lang)
{
    var cache = System.Web.HttpContext.Current.Cache;
    var rootList = cache["menu-" + Lang];
    if (rootList == null)
    {
        var list = repository.GetParts().ToList();
        cache["menu-" + Lang] = rootList;
    }
    return PartialView("SiteParts", rootList);
}

Hope this helps.

Wahid Bitar