How to RedirectToAction in ASP.NET MVC without losing request data

The solution is to use the TempData property to store the desired Request components.

For instance:

public ActionResult Send()
{
    TempData["form"] = Request.Form;
    return this.RedirectToAction(a => a.Form());
}

Then in your “Form” action you can go:

public ActionResult Form()
{
    /* Declare viewData etc. */

    if (TempData["form"] != null)
    {
        /* Cast TempData["form"] to 
        System.Collections.Specialized.NameValueCollection 
        and use it */
    }

    return View("Form", viewData);
}

Leave a Comment