MVC 4 child action's outputcache attribute not working with VaryByParam value

4.8k views Asked by At

Is it not possible to cache a child action's output depending on query value?

public class HomeController : Controller
{
    public ActionResult About()
    {
        ViewBag.Message = DateTime.Now.ToLongTimeString();

        return View();
    }

    [OutputCache(Duration = 20, VaryByParam = "id")]
    public ActionResult PartialViewTestAbout()
    {
        ViewBag.Second = DateTime.Now.Second;
        return View();
    }
}


About.cshtml

<hgroup class="title">
    <h1>@ViewBag.Title.</h1>
    <h2>@ViewBag.Message</h2>
</hgroup>


@Html.Action("PartialViewTestAbout")
.
.
.

PartialViewTestAbout.cshtml:
----------
<p>
    This is a partial view About.
    <h1 style="color:red;">@ViewBag.Message</h1>
    @ViewBag.Second
</p>

it's working good without varybyparam. But i need to refresh the PartialViewAboutTest depending on parameter.If i put the OutPutCache on About ActionREsult with VaryByParam is is working. But with child action which is PartailViewTestAbout in this example it's not working, i change the query but is't waiting for cache duration long to refresh the page...

1

There are 1 answers

0
Erhan On BEST ANSWER

the answer is, the missing id parameter that not passes into PartialViewTestAbout..

[OutputCache(Duration = 20, VaryByParam = "id")]

public ActionResult PartialViewTestAbout(int id)

this is working good.

thanks to Cem LEGOZ..:)