I have amaster page that calls render action:
<% Html.RenderAction("CategoryList", "Category", new { selectedCategoryId = Model.selectedCategoryId }); %>
and the action looks like:
[ChildActionOnly]
[OutputCache(Duration = 10, VaryByParam = "none")]
public ActionResult CategoryList(int? selectedCategoryId)
{
CategoryList cl = CategoryManager.GetList();
if (selectedCategoryId.HasValue)
CategoryManager.SetSelectedCategory(cl, selectedCategoryId.Value);
return PartialView(cl);
}
But when i run SQL profiler i see that the GetList() query is always called, meaning the action is not being cached.
开发者_C百科Any idea what i'm doing wrong?
Thanks!
It's a child action meaning that it is only a part of the final HTML and cannot be cached. For caching fragments of your HTML checkout this blog post.
its easy, use OutputCacheAttribute.
[OutputCache(Duration=60, VaryByParam="None")]
public ActionResult CacheDemo() {
return View();
}
Take care, Ragims
精彩评论