0

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.

Any idea what i'm doing wrong?

Thanks!

2 Answers 2

1

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.

2
  • I'm suprised, so what is everyone else doing with caching childactions?
    – TomerMiz
    Commented Aug 27, 2010 at 10:23
  • 1
    @user423649, they are not using ChildActions. Caching is not supported for them. Commented Aug 27, 2010 at 11:04
0

its easy, use OutputCacheAttribute.

[OutputCache(Duration=60, VaryByParam="None")]
public ActionResult CacheDemo() {
  return View();
}

Take care, Ragims

4
  • Hi, Look at the code in my question, i have [OutputCache(Duration = 10, VaryByParam = "none")], but it gets ignore since the action is called using renerAction, Any other idea?
    – TomerMiz
    Commented Aug 26, 2010 at 20:47
  • and if you try set duration to value up 30sek.?
    – r.r
    Commented Aug 27, 2010 at 8:09
  • does <%= Html.RenderAction instead <% Html.RenderAction makes any changes?
    – r.r
    Commented Aug 27, 2010 at 8:10
  • Hi, From what i saw you cannot do <%=HTML.RenderAction just: <%=HTML.Action anyway, change the action cache to: [OutputCache(Duration = 30, VaryByParam ="*")] still it doesn't cache the action and the sql profiler shows the quries, maybe Darin Dimitrov was right?
    – TomerMiz
    Commented Aug 27, 2010 at 10:23

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.