Have changed my post description because I have read that "sessions" is the right way to use. The problem is that I find it difficult using sessions, because I have never used it before.
I'm trying to link my Textboxes with an model and passing these values you enter to another view which operate on another controller. All I want is to show the values you enter in the SeatController Index page, so I then later on can use them for my booking project.
What I've got so far:
- An BookingController containing an Index view
- An SeatController containing another Index view
BookingController:
public class BookingController : Controller
{
// GET: Booking
[HttpGet]
public ActionResult Index()
{
var vm = new BookingModel();
return View(vm);
}
[HttpPost]
public ActionResult Index(BookingModel bookingModel)
{
if (ModelState.IsValid)
{
Session["SelectedValue"] = bookingModel;
return RedirectToAction("Index", "Seat", new { model = bookingModel });
}
return View(bookingModel);
}
}
BookingModel:
public class BookingModel
{
public string DepartureRoute { get; set; }
public string ReturnRoute { get; set; }
public DateTime DepartureDate { get; set; }
public DateTime ReturnDate { get; set;}
public int adults { get; set; }
public int childrens {get; set; }
}
Index (BookingController)
@model TestApplication.Models.BookingModel
@Session["SelectedValue"]
<div class="col-sm-9">
@using (Html.BeginForm())
{
<div class="col-sm-6">
<label>Outward route</label><br />
@Html.TextBoxFor(m => Model.DepartureRoute, new { @class = "textbox" })
<br />
<label>Departure date</label><br />
@Html.TextBoxFor(m => m.DepartureDate, new { @class = "textbox" })
<br />
<label>Adults:</label><br />
@Html.TextBoxFor(m => Model.DepartureRoute, new { @class = "textbox" })
</div>
<div class="col-sm-6">
<label>Return route</label><br />
@Html.TextBoxFor(m => Model.DepartureRoute, new { @class = "textbox" })
<br />
<label>Return date</label><br />
@Html.TextBoxFor(m => m.ReturnDate, new { @class = "textbox" })
<br />
<label>Childrens:</label><br />
@Html.TextBoxFor(m => Model.DepartureRoute, new { @class = "textbox" })
<br />
<label>Information:</label><br />
<button type="submit" class="button_continue">Continue</button>
</div>
}
</div>
The Index page on the "SeatController" look like this:
Index (SeatController)
<div class="col-sm-12">
<label>Departure route</label><br />
@Html.DisplayFor(model => model.DepartureRoute)
<br />
<label>Return route</label><br />
@Html.DisplayFor(m => m.ReturnRoute);
<br />
<label>Departure date</label><br />
@Html.DisplayFor(m => m.DepartureDate);
<br />
<label>Return date</label><br />
@Html.DisplayFor(m => m.ReturnDate);
<br />
<label>Number of adults</label><br />
@Html.DisplayFor(m => m.adults);
<br />
<label>Number of childrens</label><br />
@Html.DisplayFor(m => m.childrens);
</div>
Hope someone can give an solution or some guidelines how to do this.