public ActionResult Index() { TempData.Add("message", "Hello, world!"); return RedirectToAction("About"); } public ActionResult About() { string message = TempData["message"] as string; ViewBag.Message = message; return View(); }
TempData["id"] = 123; TempData.Keep("id");In this example, an id is added to TempData and then marked to be kept for the next request using the Keep method. This is useful if a redirect occurs and you need to retain the TempData data for the next request. The TempData class is part of the ASP.NET MVC framework, which is included in the Microsoft.AspNet.Mvc package library.