当其他操作调用该操作时,outputcache无法正常工作

时间:2015-06-26 08:35:53

标签: asp.net-mvc-4 outputcache

ASP.NET MVC4!

代码:

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

上面的代码运行良好。但代码:

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

无效!

我也尝试这样:

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

每个请求也不会输出相同的值!

1 个答案:

答案 0 :(得分:2)

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