Asp.net mvc 如何在ASP MVC中将局部视图设置为圆环孔

Asp.net mvc 如何在ASP MVC中将局部视图设置为圆环孔,asp.net-mvc,caching,browser-cache,donut-caching,Asp.net Mvc,Caching,Browser Cache,Donut Caching,我已经从GitHub安装了MVCDonutCache,并将其包含在我的MVC项目中 我有Home Controller的索引操作,我正在成功地对其使用缓存 [DonutOutputCache(Duration = 24 * 60 * 60, Location = System.Web.UI.OutputCacheLocation.Any)] public ActionResult Index() { return View(); } 在我看来,我

我已经从GitHub安装了MVCDonutCache,并将其包含在我的MVC项目中

我有Home Controller的索引操作,我正在成功地对其使用缓存

    [DonutOutputCache(Duration = 24 * 60 * 60, Location = System.Web.UI.OutputCacheLocation.Any)]
    public ActionResult Index()
    {
        return View();
    }
在我看来,我称之为两种局部观点

<div class="container">
    @Html.Partial("BlogPosts")
    @Html.Partial("RightSideBar")
</div>

@Html.Partial(“博客帖子”)
@Html.Partial(“右侧边栏”)
View BlogPost是动态的,所以我不希望缓存它,但RightSideBar需要缓存

那么,如何设置博客帖子不被缓存呢
DonutOutputCache设置要缓存的总视图(包括两个局部视图)

如果您想利用MVCDonutCache的“甜甜圈”功能,您必须在控制器(即BlogPost())中创建一个返回局部视图的操作

[ChildActionOnly]
public ActionResult BlogPosts() {
    // ...
    return PartialView("BlogPosts", posts)
}
一旦有了此功能,您可以修改初始视图以使用一个库HtmlHelpers:

@Html.Action("BlogPosts", true)
问候