Search code examples
asp.net-mvcfacebook-c#-sdkredirecttoaction

Facebook SDK MVC CanvasRedirectToAction


I'm trying to pass some value using TempData["SomeValue"] to another action using this.RedirectToAction("Action");

    public ActionResult TestTempData()
    {
        TempData["TeamId"] = 1;
        return Facebook.Web.Mvc.CanvasControllerExtensions.CanvasRedirectToAction(this,"TestTempData2");
    }

    public ActionResult TestTempData2()
    {
        if (TempData["TeamId"] == null)
            ViewBag.Title = "NOT FOUND";
        ViewBag.Title = "FOUND";

        return View("Index");
    }

But on the "Action" TempData is always empty can someone help me with this ?


Solution

  • This is because the CanvasRedirectToAction method redirects by writing out a javascript function that then executes when the TestTempData action is loaded.

    TempData is only preserved for server-side redirects. If you use RedirectToAction you will have your TempData but the url bar will not change to reflect the current page.