Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Sep 02, 2008 01:43 AM by tgmdbm
Sep 02, 2008 01:10 AM|LINK
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?
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)