是否无法根据查询值缓存子操作的输出?
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>
没有varybyparam,它的工作正常。但我需要刷新PartialViewAboutTest取决于参数。如果我把OutPutCache放在关于ActionREsult与VaryByParam是工作。但是在这个示例中,子动作是PartailViewTestAbout,它不起作用,我改变了查询,但是不等待缓存持续时间很长时间来刷新页面......
答案 0 :(得分:3)
答案是,缺少的id参数未传递给PartialViewTestAbout ..
[OutputCache(Duration = 20, VaryByParam = "id")]
public ActionResult PartialViewTestAbout(int id)
这很有效。
感谢Cem LEGOZ .. :)