加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 跨多个页面的MVC3 RenderPartial缓存

发布时间:2020-12-16 04:17:02 所属栏目:asp.Net 来源:网络整理
导读:任何人都可以告诉我是否可以跨多个页面缓存RenderPartial?我有一个用户配置文件的RenderPartial,除非用户更新其配置文件,否则不应该真正改变.因此,每次加载页面时,我都不想回去获取他/她的个人资料.我宁愿传递部分内容直到我被迫更新(即个人资料更新) 我查
任何人都可以告诉我是否可以跨多个页面缓存RenderPartial?我有一个用户配置文件的RenderPartial,除非用户更新其配置文件,否则不应该真正改变.因此,每次加载页面时,我都不想回去获取他/她的个人资料.我宁愿传递部分内容直到我被迫更新(即个人资料更新)

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

解决方法

您可以改用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.cshtml和About.cshtml视图中,您可以包含子操作:

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读