Skip to main content

Posts

Showing posts with the label ViewBag and TempData in MVC

ViewData, ViewBag and TempData in MVC

ViewData, ViewBag and TempData in MVC explained ViewBag  and  ViewData  are used to pass the data from Controller action to View and  TempData  is used to pass the data from action to another action or one Controller to another Controller. ViewData and ViewBag are used for the same purpose that is, to transfer data from controller to view.  ViewData is nothing but a dictionary of objects and it is accessible by string as key. ViewData is a property of controller that exposes an instance of the  ViewDataDictionary class. ViewBag is very similar to ViewData, but ViewBag is a dynamic property (dynamic keyword is introduced in .net framework 4.0). ViewBag is able to set and get value dynamically and able to add any number of additional fields without converting it to strongly typed. ViewBag is just a wrapper around the ViewData. ViewData 1.        ViewData is derived from the  ViewDataDictionary ...