ASP.NET MVC TempData object is used to share data between controller actions.It is a dictionary object derived from TempDataDictionary.
The value of TempData persists until it is read or until the current users session times out.TempdData can be used to maintain data between
controller actions as well as between redirects.
In the below code we illustrate how TempData can be used to pass data from one controller action to another.
// We store a file object in (TemporaryFile)
public ActionResult TemporaryFile()
{
File file = new File
{
FileID = "112",
FileName = "Checklist",
FileType = "Excel"
};
TempData["File"] = file;
return RedirectToAction("PermanentFile");
}
//We retrieve a file object in (PermanentFile)
public ActionResult PermanentFile()
{
File file = TempData["File"] as File;
return View(file);
}
0 Comment(s)