谁能告诉我是否可以跨多个页面缓存 RenderPartial?我有一个用于用户配置文件的 RenderPartial,除非用户更新其配置文件,否则它实际上不会改变。所以我真的不想每次加载页面时都回去获取他/她的个人资料。我宁愿传递部分内容,直到我被迫更新(即个人资料更新)
我看了看甜甜圈洞 http://haacked.com/archive/2009/05/12/donut-hole-caching.aspxp.haack 放在一起的示例,但它似乎与单个页面相关。有人可以指出我正确的方向或提供任何建议吗?或者我一次只能缓存一页?谢谢!
您可以改用 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
and About.cshtml
您可以包含子操作的视图:
<div>
@{Html.RenderAction("Cached");}
</div>
您将在两个页面中获得它的缓存版本。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)