0

I would like to know how I can pass values from one action to another action without redirecting to that controller.

For example, I want to pass values from my "Index" action to my "reservation_step_2" action without having to redirect to that page but instead to my "reservation_step_1" page.

 [HttpPost]
    public ActionResult Index(string locationId, string dt1, string dt2, string PickUpTime, string DropOffTime)
    {
        string loc = locationId;
        string PUT = PickUpTime;
        string DOT = DropOffTime;
        DateTime d_in = DateTime.ParseExact(dt2.Trim(), "dd/M/yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat);
        DateTime d_out = DateTime.ParseExact(dt1.Trim(), "dd/M/yyyy", System.Globalization.CultureInfo.CurrentUICulture.DateTimeFormat);

        return RedirectToAction("reservation_step_1", "Home", new { d_out = d_out, d_in = d_in, loc = loc, PU_time = PUT, DO_time = DOT});
    }

I would like to pass d_out, d_in, PU_time and DO_time to "reservation_step_2" but pass loc to "reservation_step_1" and redirect to "reservation_step_1"

How can I go about doing this?

Daniel
  • 107
  • 1
  • 12
  • Looks like you need [this](https://stackoverflow.com/q/799511/728795) – Andrei Aug 16 '18 at 15:41
  • 1
    If you are just trying to save values for use later in another page, why not just save them into a database and pull them back when they navigate to that page, or you could just store them in the Session? – Ryan Wilson Aug 16 '18 at 15:45
  • @RyanWilson Please correct me if I am wrong, If i say `Session["PUT"] = PickUpTime;` in my index action and if I say `var PU_Time = Session["PUT"];` in my reservations_step_2 action, would `PU_Time` hold the value from my index action? – Daniel Aug 16 '18 at 15:58
  • @Daniel You got it sir. – Ryan Wilson Aug 16 '18 at 16:48

0 Answers0