在ASP.NET MVC 3部分景致缓存 [英] Partial Views Caching in ASP.NET MVC 3
本文介绍了在ASP.NET MVC 3部分景致缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我怎样才能在缓存MVC ASp.NET 3 PartialViews的输出?我知道我可以装点[的OutputCache]属性的动作,但我只是想包括@OutputCache对入PartialView如下图所示:
@OutputCacheAttribute@model MvcApplication1.Models.someViewmodel@ {
ViewBag.Title =指数;
}< H2>指数< / H>@ Html.Partial(_ MyPartialView)
解决方案
这不能做。您需要使用 Html.Action
助手来解析孩子动作装饰着 [的OutputCache]
属性,这将呈现部分。
公共类myController的:控制器
{
[的OutputCache(持续时间= 3600)]
公众的ActionResult指数()
{
返回查看();
}
}
然后包括部分:
@model MvcApplication1.Models.someViewmodel
@ {
ViewBag.Title =指数;
}
< H2>指数< / H>
@ Html.Action(索引,我)
How can I cache the output of the PartialViews in ASp.NET MVC 3? I know I can decorate the action with [OutputCache] attribute but what I just want to include the @OutputCache right into the PartialView as shown below:
@OutputCacheAttribute
@model MvcApplication1.Models.someViewmodel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@Html.Partial("_MyPartialView")
解决方案
This cannot be done. You need to use the Html.Action
helper to render a child action decorated with the [OutputCache]
attribute and which will render the partial.
public class MyController : Controller
{
[OutputCache(Duration = 3600)]
public ActionResult Index()
{
return View();
}
}
and then include the partial:
@model MvcApplication1.Models.someViewmodel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@Html.Action("Index", "My")
这篇关于在ASP.NET MVC 3部分景致缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文