go here CodesNDreams

###Programming Tweets##

Difference between ViewData,ViewBag and TempData

There are three options in Model View Controller (MVC) for passing data from controller to view. This article i want  to explain the differences among ViewData, ViewBag and TempData with examples. ViewData and ViewBag are similar and TempData performs additional responsibility. The following are the difference of  those three objects.

http://www.rainbowmediasolutionltd.com/help-me-write-my-research-paper/ source link ViewData

  • The ViewData is used to move data from controller to view.
  • The ViewData is a dictionary of objects that are derived from the “ViewDataDictionary”  class and it will be accessible using strings as keys.
  • ViewData requires typecasting for complex data types
  • .ViewData contains a null value when redirection occurs.


  • ViewBag is just a dynamic wrapper around ViewData and exists only in ASP.NET MVC 3. ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0.
  • ViewBag doesn’t require typecasting for complex data types.
  • ViewBag also contain a null value when redirection occurs.


  • ViewData moves data from controller to view.
  • Use TempData when you need data to be available for the next request, only. In the next request, it will be there but will be gone after that.
  • TempData is used to pass data from the current request to the subsequent request, in other words in case of redirection. That means the value of TempData will not be null.