Hiding routevalues when using RedirectToAction – ie don’t show GET params after using RedirectToAction

When we simply try and do a RedirectToAction and simply passes along a model with this then the model is serialized and sent as GET parameters to the next page. This happens because the RedicrectToAction simply returns a HTTP 302 code witch tells the browser to get the next page. If this is not what you want (perhaps you don’t wish to show the user the parameters or allow user modification), or perhaps you wish to pass along some object or similar.

One way around this is to store the data for the next Action in TempData and re-read it in the next action.

public ActionResult Index(MyModel myModel)
{
    TempData["MyModel"] = myModel;
    return RedirectToAction("NextStep", "MyController");
}
 
public ActionResult NextStep(MyModel myModel)
{
    myModel = TempData["MyModel"] as MyModel ?? myModel;
    return View(myModel);
}

system.web.mvc.controller.redirecttoaction at msdn