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
2009-06-09 12:46:27
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
2009-06-09 13:00:03
+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
2009-06-09 13:04:56
+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:
- Items are only removed from
TempData
at the end of a request if they have been tagged for removal. - Items are only tagged for removal when they are read.
- Items may be untagged by calling
TempData.Keep(key)
. RedirectResult
andRedirectToRouteResult
always callsTempData.Keep()
.
ongle
2009-12-16 19:50:52