tags:

views:

259

answers:

3

I'd like to know what the scope and visibility of TempData is in ASP.NET MVC.

+1  A: 

According to MSDN, TempData, an instance of TempDataDictionary, is available in classes that derive from ControllerBase, ViewContext, and ViewPage. The data only lasts for a single round-trip: set in one request, removed after the next request.

tvanfosson
Well sorry for this kind of comment but I can't open any of the microsoft's websites! And I don't now why? anyway I got the answer! Thanks.
Vikas
+1  A: 

TempData is not accessible (set to null) in Views using post-cache substitution (HttpResponse.WriteSubstitution() Method). See http://stackoverflow.com/questions/683646/asp-net-mvc-donut-caching-and-tempdata for more details.

eu-ge-ne
+2  A: 

For others... ASP.NET MVC 2 has made some changes to TempData. Here is a blog entry with details. In summary:

...The outcome of the changes we made resulted in the following rules that govern how TempData operates:

  1. Items are only removed from TempData at the end of a request if they have been tagged for removal.
  2. Items are only tagged for removal when they are read.
  3. Items may be untagged by calling TempData.Keep(key).
  4. RedirectResult and RedirectToRouteResult always calls TempData.Keep().
ongle