What is the scope of TempData in ASP.NET MVC?

I would like to know what the scope of TempData is in ASP.NET MVC.

+6
asp.net-mvc
source share
3 answers

According to MSDN, TempData, an instance of TempDataDictionary is available in classes that derive from ControllerBase , ViewContext, and ViewPage . Data is saved only during one round: set in one request, deleted after the next request.

+5
source share

For others ... ASP.NET MVC 2 has made some changes to TempData. Below is a blog post . In short:

... The result of the changes led to the following rules that determine how TempData works:

  • Items are only deleted with TempData at the end of the query if they were marked for deletion.
  • Items are marked for deletion only when they are read.
  • Elements can be untagged by calling TempData.Keep(key) .
  • RedirectResult and RedirectToRouteResult always calls TempData.Keep() .
+14
source share

TempData is not available (set to null) in views using post-cache substitution (HttpResponse.WriteSubstitution () method). See ASP.NET MVC Donut Caching and TempData for more details.

+1
source share

All Articles