views:

32

answers:

2

Hi All,

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!

+1  A: 

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.

Darin Dimitrov
I'm suprised, so what is everyone else doing with caching childactions?
TomerMiz
@user423649, they are not using ChildActions. Caching is **not** supported for them.
Darin Dimitrov
A: 

Hey.

its easy, use OutputCacheAttribute.

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

Take care, Ragims

Ragims
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
and if you try set duration to value up 30sek.?
Ragims
does <%= Html.RenderAction instead <% Html.RenderAction makes any changes?
Ragims
Hi,From what i saw you cannot do<%=HTML.RenderActionjust:<%=HTML.Actionanyway, 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