简体   繁体   English

如何在ASP MVC中将局部视图设置为甜甜圈孔

[英]How to set a partial view as donut hole in ASP MVC

i have installed mvcdonutcaching from GitHub and included it in my MVC Project 我已经从GitHub安装了mvcdonutcaching并将其包含在我的MVC项目中

i have the Index Action for Home Controller and i am successfully using Caching on it 我具有Home Controller的Index Action,并且我已成功在其上使用缓存

    [DonutOutputCache(Duration = 24 * 60 * 60, Location = System.Web.UI.OutputCacheLocation.Any)]
    public ActionResult Index()
    {
        return View();
    }

and in my view i am calling 2 Partial Views . 在我看来,我称之为2部分视图。

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

View BlogPost is dynamic so i don't want it to be cached but RightSideBar needs to be cached View BlogPost是动态的,因此我不希望将其缓存,但是RightSideBar需要缓存

so how can i set the BlogPost not to be cached the DonutOutputCache sets the total view to be cached including both partial views 所以如何设置不缓存BlogPost DonutOutputCache设置要缓存的总视图,包括两个局部视图

If you want to take advantage of MvcDonutCaching "donut" ability, you have to create an Action in your controller (ie. BlogPost()) that returns your PartialView. 如果要利用MvcDonutCaching的“甜甜圈”功能,则必须在控制器中创建一个Action(即BlogPost())以返回PartialView。

[ChildActionOnly]
public ActionResult BlogPosts() {
    // ...
    return PartialView("BlogPosts", posts)
}

Once you have this, you can modify your initial view to use one the library HtmlHelpers : 一旦有了这个,就可以修改您的初始视图以使用HtmlHelpers库之一:

@Html.Action("BlogPosts", true)

Regards. 问候。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM