Wednesday, February 22, 2012

ViewBag – ViewData – TempData objects

August 11, 2011 by · Leave a Comment 

All of them are properties of Controllers and Views, and all of them are used to transport very small amount of data between pages.

ViewData: It is of dictionary type, used to store key/value pairs and transmit them between controllers and views.

ViewBag: It is a wrapper built above ViewData, but it is dynamic in nature as appose to ViewData.

TempData: It is also a dictionary type property, but it is only used between subsequent request and is very short lived

 

While redirecting from one controller, both ViewBag and ViewData properties cannot be used, but TempData property can be used to transport data, as it works for subsequent requests.

Top Blogs

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

*