0

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.

3
  • model is null in FinalBooking or MakeBooking to? Commented Dec 5, 2013 at 14:44
  • 1
    Could you share the relevant portion of your view, too? Commented Dec 5, 2013 at 14:44
  • You need to check the model state before assuming the post was correct. Check ModelState.IsValid and if false, return the model back to the view and it will display any validation errors in the validation section. There is also an errors collection you can parse for diagnostic information. Commented Dec 5, 2013 at 14:46

2 Answers 2

2

It should work

return RedirectToAction("FinalBooking", "Booking", model);
Sign up to request clarification or add additional context in comments.

1 Comment

Would rep this if I could, used it elsewhere in project now :)
0

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.

1 Comment

Exactly. Redirect To Action is going to issue an http redirect code to the client (302 I think) and the new action will be invoked. This means the values set in the third param are route values.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.