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);
}
每个请求也不会输出相同的值!
答案 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());
}