开发者

ASP.NET MVC 2 controller not cached

开发者 https://www.devze.com 2023-01-13 10:16 出处:网络
I have amaster page that calls render action: <% Html.RenderAction(\"CategoryList\", \"Category\", new { selectedCategoryId = Model.selectedCategoryId });%>

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

精彩评论

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