问题描述
我正在开发一个网站,MVC 5.2.3,它在 _Layout.cshtml
A顶部的菜单栏包含登录的用户信息。如用户的全名,所以它不应该是缓存。结果
对于排除的OutputCache这个菜单中,我创建了一个孩子的行动吧。
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");
}
在这之后,我安装了 MvcDonutCaching
的NuGet包,并用它在 _Layout.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.
我应该如何从MVC删除此子操作的OutputCache
How should I remove this child action from MVC OutPutCache
推荐答案
我发现这个问题,结果
我没有使用 DonutOutputCache
有关行动输出缓存属性,我用的OutputCache
来代替。结果
我改成了 DonutOutputCache
,而在的Application_Start
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.
这篇关于从在的OutputCache MVC 5删除ChildAction?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!