MVC3 RenderPartial 跨多个页面缓存

发布于 2024-10-20 01:53:13 字数 327 浏览 4 评论 0 原文

谁能告诉我是否可以跨多个页面缓存 RenderPartial?我有一个用于用户配置文件的 RenderPartial,除非用户更新其配置文件,否则它实际上不会改变。所以我真的不想每次加载页面时都回去获取他/她的个人资料。我宁愿传递部分内容,直到我被迫更新(即配置文件更新)

我查看了 DonutHole p.haack 放在一起的示例,但它似乎与单个页面相关。有人可以指出我正确的方向或提供任何建议吗?或者我一次只能缓存一页?谢谢!

Can anyone tell me if its possible to Cache a RenderPartial across multiple pages? I have a RenderPartial for a user profile that shouldn't really ever change unless the user updates their profile. So i dont really want to go back and get his/her profile every time i load a page. I would much rather pass the partial around until im forced to update (i.e. profile update)

I looked at the DonutHole example that p.haack put together, but it seems to be relevant for a single page. Can someone point me in the right direction or offer any advice? Or am i only able to cache one page at a time? thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅 2024-10-27 01:53:13

您可以改用 RenderAction。示例:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult About()
    {
        return View();
    }

    [OutputCache(Duration = 6000, VaryByParam = "none")]
    public ActionResult Cached()
    {
        // You could return whatever you want here, even a view
        // but for the purpose of the demonstration I am simply
        // returning a dynamic string value
        return Content(DateTime.Now.ToLongTimeString(), "text/html");
    }
}

Index.cshtmlAbout.cshtml 视图中,您可以包含子操作:

<div>
    @{Html.RenderAction("Cached");}
</div>

并且您将在两个页面中获得它的缓存版本。

You could use RenderAction instead. Example:

public class HomeController : Controller
{
    public ActionResult Index()
    {
        return View();
    }

    public ActionResult About()
    {
        return View();
    }

    [OutputCache(Duration = 6000, VaryByParam = "none")]
    public ActionResult Cached()
    {
        // You could return whatever you want here, even a view
        // but for the purpose of the demonstration I am simply
        // returning a dynamic string value
        return Content(DateTime.Now.ToLongTimeString(), "text/html");
    }
}

and inside the Index.cshtml and About.cshtml views you could include the child action:

<div>
    @{Html.RenderAction("Cached");}
</div>

and it you will get the cached version of it in both pages.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文