smallerpig
smallerpig

Reputation: 27

outputcache not working when the action called by other action

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!

Upvotes: 0

Views: 185

Answers (1)

Kaushik Thanki
Kaushik Thanki

Reputation: 3510

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());
    }

Upvotes: 2

Related Questions