Use A Cookie To Send PersonID To Different Page
-
Hey guys so atm when the user goes to the holiday page, they can do 1 of 2 things 1)use a drop down box to select 'person name' and click 'view' this will display all the current holidays for this person 2)click 'create new' which will bring the user to a create page which allows them to add a new holiday(from here they select person name from drop and and select what date from calender) This all works, however if the user originally follows the first path of selecting a person name and clicking view(it will display their holidays) if they then take the path of 2 and click 'create' it will jump to the create page. however the drop down box will be back at 'select' i would like the existing person selected from the previous drop down to display in this drop down. A cookie or url/parameter? anyway Im stuck please help I've tried a cookie.
[code]
[HttpGet]
public ViewResult Index(string sortOrder, int? currentPersonID)
{
var holidays = db.Holidays.Include("Person");
HolidayList model = new HolidayList();if (currentPersonID.HasValue) { model.currentPersonID = currentPersonID.Value; } else { model.currentPersonID = 0; } model.PList4DD = db.People.ToList(); //hyperlink to sort dates in ascending order ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "date" : ""; var dates = from d in db.Holidays where d.PersonId == currentPersonID.Value select d; switch (sortOrder) { case "date": dates = dates.OrderBy(p => p.HolidayDate); break; } model.HList4DD = dates.ToList(); var cookie = new HttpCookie("cookie\_name", "currentPersonID"); Response.AppendCookie(cookie); return View(model); } public ActionResult Create() { var cookie = Request.Cookies\["cookie\_name"\]; if (cookie != null) { string value = cookie.Value; //int? value = cookie.Value; } ViewBag.cookie = cookie.Value; ViewBag.Id = new SelectList(db.People, "Id", "Name"); return View();
//tried to use the currentPersonID in index as an int but it wou