📅  最后修改于: 2023-12-03 14:53:22.826000             🧑  作者: Mango
The TempData[] feature in ASP.NET Core is a special dictionary object that helps us to persist data between requests. We can use it to store data when we redirect from one action to another action.
We can use TempData[] with the help of the following steps:
public IActionResult Index()
{
TempData["Message"] = "Hello World!";
return RedirectToAction("About");
}
public IActionResult About()
{
var message = TempData["Message"];
return View();
}
public IActionResult About()
{
var message = TempData["Message"];
TempData.Remove("Message");
return View();
}
TempData[] enables us to store data temporarily in a dictionary object that can persist between requests. We can use it to pass data from one action to another action in a controller. It is an essential tool for any ASP.NET Core developer.