Can somebody please explain the purpose of TempData in MVC. I understand it behaves like ViewBag but what does it do beyond that.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- MVC-Routing,Why i can not ignore defaults,The matc
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
ViewBag
Allows you to create dynamic properties
Passing data between the controller and view
Controller
ViewBag.Name= "Lion";
View
TempData
TempData is meant to be a very short-lived instance
you should only use it during the current and the subsequent requests only
TempData dictionary is used to share data between controller actions
I have written Blog post about this.Check that How to use Asp.Net MVC TempData Properly ?
http://rachelappel.com/when-to-use-viewbag-viewdata-or-tempdata-in-asp.net-mvc-3-applications
TempData is a dictionary object that is derived from TempDataDictionary class and stored in short lives session.
It is a property of ControllerBase class.It is used to pass data from current request to subsequent request (means redirecting from one page to another). It’s life is very short and lies only till the target view is fully loaded. It’s required typecasting for getting data and check for null values to avoid error.It is used to store only one time messages like error messages, validation messages.