outputcache not working when the action called by other action

196 views Asked by At

ASP.NET MVC4!

the code :

    [OutputCache(Duration = int.MaxValue, VaryByParam = "id")]
    public ActionResult Index(int id = 0)
    {
        return Content(DateTime.Now.ToString());
    }

the code above working well. but the code:

    public ActionResult Index(int id = 0)
    {
        ActionResult result = Test(id);

        return result;
    }

    [OutputCache(Duration = int.MaxValue, VaryByParam = "id")]
    ActionResult Test(int id)
    {
        return Content(DateTime.Now.ToString());
    }

is not working!

i also try like this:

    public ActionResult Index(int id = 0)
    {
        return Test(id);
    }

it's also not output the same value each request!

1

There are 1 answers

1
Kaushik Thanki On

You should use

return RedirectToAction("Index", "Home", new { id = 1 });

Like This Way.

public ActionResult Index(int id = 0)
    {
         return RedirectToAction("Test", "Home", new { id = 1 });
    }

    [OutputCache(Duration = int.MaxValue, VaryByParam = "id")]
    ActionResult Test(int id)
    {
        return Content(DateTime.Now.ToString());
    }