0

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!

smallerpig
  • 27
  • 5

1 Answers1

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());
    }
Kaushik Thanki
  • 3,334
  • 3
  • 23
  • 50
  • but what's can i do when request is from the app like android or iphone?this way will not get the correct result,because this is not the way Response.write() but set the response head location value to hostname/home/test/id! by the way, I use ApiController! – smallerpig Jun 27 '15 at 03:19