public ActionResult About() { ViewBag.Message = "Fetch the values saved in the Index() method"; // Fetch; test existence first int myAge; if (Session["myAge"] != null) { myAge = (int)Session["myAge"]; } else { myAge = 0; } // Fetch string myName; if (Session["myName"] != null) { myName = (string)Session["myName"]; } else { myName = ""; } // Fetch List<string> colours; if (Session["colours"] != null) { colours = (List<string>)Session["colours"]; } else { colours = new List<string>(); } // Fetch List<Person> teachers; if (Session["teachers"] != null) { teachers = (List<Person>)Session["teachers"]; } else { teachers = new List<Person>(); } // Prepare data to pass to the view AboutViewModel answers = new AboutViewModel(); answers.MyAge = myAge; answers.MyName = myName; answers.Colours = colours; answers.Teachers = teachers; return View(answers); }
public ActionResult About() { ViewBag.Message = "Fetch the values saved in the Index() method"; // Fetch; test existence first int myAge; if (Session["myAge"] != null) { myAge = (int)Session["myAge"]; } else { myAge = 0; } // Fetch string myName; if (Session["myName"] != null) { myName = (string)Session["myName"]; } else { myName = ""; } // Fetch List <string> colours; if (Session["colours"] != null) { colours = (List <string>)Session["colours"]; } else { colours = new List <string>(); } // Fetch List <Person> teachers; if (Session["teachers"] != null) { teachers = (List <Person>)Session["teachers"]; } else { teachers = new List <Person>(); } // Prepare data to pass to the view AboutViewModel answers = new AboutViewModel(); answers.MyAge = myAge; answers.MyName = myName; answers.Colours = colours; answers.Teachers = teachers; return(View(answers)); }