public ActionResult WriteTempData(Contact contact) { TempData["ContactInformation"] = contact; TempData["SuccessMessage"] = "Great job"; return RedirectToAction("ReadTempData"); }
public ActionResult WriteCookie(Contact contact) { HttpCookie myCookie = CreateCookie(); myCookie["Name"] = contact.Name; myCookie["Email"] = contact.Email; Response.Cookies.Add(myCookie); return RedirectToAction("ReadCookie"); }
public ActionResult ReadCookie() { Contact contact = new Contact(); var cookie = Request.Cookies[CookieName]; if (cookie != null) { contact.Name = cookie["Name"]; contact.Email = cookie["Email"]; } else { contact.Name = "No Cookie"; } return View(contact); }
public ActionResult ReadSession() { Contact contact = new Contact(); if (Session["ContactInformation"] != null) { contact = (Contact) Session["ContactInformation"]; } else { contact = new Contact() { Name = "No Session", Email = "Fail!" }; } return View(contact); }
public ActionResult ReadTempData() { Contact contact = new Contact(); if (TempData["ContactInformation"] != null) { contact = (Contact)TempData["ContactInformation"]; } else { contact = new Contact() { Name = "No TempData", Email = "Fail!" }; } //string msg; //if (TempData["SuccessMessage"] != null) //{ // msg = (string)TempData["SuccessMessage"]; //} //else //{ // msg = "No message"; //} return View(contact); }
public ActionResult WriteSession(Contact contact) { Session["ContactInformation"] = contact; return RedirectToAction("ReadSession"); }