I'm developing a website with MVC 5.2.3, it has a top menu bar in _Layout.cshtml
that contains logged in user information. Like user's FullName, so it shouldn't be cache.
For exclude this menu from OutPutCache, I created a child action for it.
[ChildActionOnly]
public PartialViewResult TopMenu()
{
return PartialView("~/Views/Partials/TopMenuPartial.cshtml");
}
After that, I installed MvcDonutCaching
nuget package and use it in _Layout.cshtml
as the following:
@Html.Action("TopMenu", "Home", true)
But, it doesn't work, and if someone login, it's FullName came in top menu bar for all clients.
How should I remove this child action from MVC OutPutCache
I found the problem,
I didn't use DonutOutputCache
attribute for output cache on actions, I used OutPutCache
instead.
I changed it to DonutOutputCache
, and add the following setting in Application_Start
protected void Application_Start()
{
...
DevTrends.MvcDonutCaching.OutputCache.DefaultOptions = DevTrends.MvcDonutCaching.OutputCacheOptions.ReplaceDonutsInChildActions;
...
}
Now, my problem solved.