如何在ASp.NET MVC 3中缓存PartialViews的输出?我知道我可以用[OutputCache]属性修饰动作,但我只想将@OutputCache包含在PartialView中,如下所示:
@OutputCacheAttribute
@model MvcApplication1.Models.someViewmodel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@Html.Partial("_MyPartialView")
Run Code Online (Sandbox Code Playgroud)
Dar*_*rov 22
这是不可能做到的.您需要使用Html.Action
帮助器来呈现使用该[OutputCache]
属性修饰的子动作,并且该动作将呈现部分动作.
public class MyController : Controller
{
[OutputCache(Duration = 3600)]
public ActionResult Index()
{
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
然后包括部分:
@model MvcApplication1.Models.someViewmodel
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
@Html.Action("Index", "My")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
12101 次 |
最近记录: |