开发者

ASP.NET MVC 2 controller not cached

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜