The fact that ViewData is now on ControllerBase and not Controller doesn't affect you very much. You use it just the same. But if you're writing ActionFilters then you don't need to cast context.Controller to the Controller type to access ViewData, you can
just do context.Controller.ViewData.
The difference between ViewData and TempData: ViewData is created in the controller, passed to the View, used, then forgotten about, TempData is stored in the Session, its a way of persisting data across a single request, on the very next request, the TempData
is taken from the Session and then removed so it doesn't appear twice. TempData is usually used to store validation errors before doing a redirect back to the previous page. (if you've used RoR it's the same as the Flash object)
Marked as answer by shapper on Sep 02, 2008 01:56 AM
shapper
Contributor
3932 Points
3789 Posts
ViewData and TempData in Preview 5
Sep 02, 2008 01:10 AM|LINK
Hello,
On Preview 5 Release Notes it is said:
"The abstract Controller class now derives from ControllerBase, which contains useful properties such as ViewData and TempData."
The way I use ViewData changes? How should I use this new property in my controller?
And what is the difference between ViewData and TempData?
Thanks,
Miguel
tgmdbm
Contributor
4392 Points
883 Posts
ASPInsiders
MVP
Re: ViewData and TempData in Preview 5
Sep 02, 2008 01:43 AM|LINK
The fact that ViewData is now on ControllerBase and not Controller doesn't affect you very much. You use it just the same. But if you're writing ActionFilters then you don't need to cast context.Controller to the Controller type to access ViewData, you can just do context.Controller.ViewData.
The difference between ViewData and TempData: ViewData is created in the controller, passed to the View, used, then forgotten about, TempData is stored in the Session, its a way of persisting data across a single request, on the very next request, the TempData is taken from the Session and then removed so it doesn't appear twice. TempData is usually used to store validation errors before doing a redirect back to the previous page. (if you've used RoR it's the same as the Flash object)