本文介绍了在多个页面MVC3的RenderPartial缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以,如果可能告诉我在多个页面缓存的RenderPartial?我有应该不是真的永远改变的,除非用户更新他们的配置文件的用户配置文件的RenderPartial。所以,我不是真的想回去,每次我打开一个网页的时间得到他/她的个人资料。我宁愿通过局部周围,直到IM被迫更新(即简介更新)

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)

我看着例子是p .haack放在一起,但它似乎是相关的单个页面。有人能指出我在正确的方向或提供任何意见?还是我只能够一次缓存一个页面?谢谢!

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!

推荐答案

您可以使用替代的RenderAction。例如:

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");
    }
}

Index.cshtml About.cshtml 的意见里面,你可以包括子操作:

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.

这篇关于在多个页面MVC3的RenderPartial缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 19:48