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

408 views Asked by At

i have installed mvcdonutcaching from GitHub and included it in my MVC Project

i have the Index Action for Home Controller and i am successfully using Caching on it

    [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 .

<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

so how can i set the BlogPost not to be cached the DonutOutputCache sets the total view to be cached including both partial views

1

There are 1 answers

0
moonpyk On

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.

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

Once you have this, you can modify your initial view to use one the library HtmlHelpers :

@Html.Action("BlogPosts", true)

Regards.