【发布时间】:2013-09-01 14:32:52
【问题描述】:
是否不能根据查询值缓存子操作的输出?
public class HomeController : Controller
{
public ActionResult About()
{
ViewBag.Message = DateTime.Now.ToLongTimeString();
return View();
}
[OutputCache(Duration = 20, VaryByParam = "id")]
public ActionResult PartialViewTestAbout()
{
ViewBag.Second = DateTime.Now.Second;
return View();
}
}
About.cshtml
<hgroup class="title">
<h1>@ViewBag.Title.</h1>
<h2>@ViewBag.Message</h2>
</hgroup>
@Html.Action("PartialViewTestAbout")
.
.
.
PartialViewTestAbout.cshtml:
----------
<p>
This is a partial view About.
<h1 style="color:red;">@ViewBag.Message</h1>
@ViewBag.Second
</p>
在没有可变参数的情况下运行良好。但是我需要根据参数刷新 PartialViewAboutTest。如果我将 OutPutCache 放在 About ActionREsult 上,并且 VaryByParam 正在工作。但是在本例中使用 ParttailViewTestAbout 的子操作不起作用,我更改了查询但没有等待缓存持续时间很长来刷新页面...
【问题讨论】:
标签: asp.net-mvc-4 outputcache child-actions varybyparam