MVC - ViewData VS ViewBag VS TempData

ViewData VS ViewBag VS TempData

ViewData
ViewBag
TempData
It is Key-Value Dictionary collectionIt is a type objectIt is Key-Value Dictionary collection
ViewData is a dictionary object and it is property of ControllerBase classViewBag is Dynamic property of ControllerBase class.TempData is a dictionary object and it is property of controllerBase class.
ViewData is Faster than ViewBagViewBag is slower than ViewDataNA
ViewData is introduced in MVC 1.0 and available in MVC 1.0 and aboveViewBag is introduced in MVC 3.0 and available in MVC 3.0 and aboveTempData is also introduced in MVC1.0 and available in MVC 1.0 and above.
ViewData also works with .net framework 3.5 and aboveViewBag only works with .net framework 4.0 and aboveTempData also works with .net framework 3.5 and above
Type Conversion code is required while enumeratingIn depth, ViewBag is used dynamic, so there is no need to type conversion while enumerating.Type Conversion code is required while enumerating
Its value becomes null if redirection has occurred.Same as ViewDataTempData is used to pass data between two consecutive requests.
It lies only during the current request.Same as ViewDataTempData only works during the current and subsequent request

Yorumlar