Reputation: 33
Form posts from webpage MakeBooking
to FinalBooking
to ascertain certain information such as number of guests, so the FinalBooking
page can give you enough textboxes to input guest information for all guests required.
When in debug mode, both models in MakeBooking
post are populated. After post, in FinalBooking
, model is null.
[HttpPost]
public ActionResult MakeBooking(BookingModel model)
{
return RedirectToAction("FinalBooking", "Booking", new { model = model });
}
public ActionResult FinalBooking(BookingModel model)
{
return View(model);
}
Any info would be appreciated.
Upvotes: 0
Views: 1118
Reputation: 7836
It should work
return RedirectToAction("FinalBooking", "Booking", model);
Upvotes: 2
Reputation: 218722
You can not pass a model with RedirectToAction
like that. you need to use either TempData or Session to transfer the model object between your calls.
RedirectToAction
method returns an HTTP 302 response to the browser, which causes the browser to make a GET request to the specified action.
The below example shows how to transfer data using TempData.
[HttpPost]
public ActionResult MakeBooking(BookingModel model)
{
TempData["TempBookingModel"]=model;
return RedirectToAction("FinalBooking", "Booking");
}
public ActionResult FinalBooking()
{
var model= TempData["TempBookingModel"] as BookingModel;
return View(model);
}
Internally TempData
is using Session as the storage mechanism.
Upvotes: 0