ViewBag Vs TempData.

Posted by  Nishi Tiwari
 169  View(s)
Rate this:
  1. ViewBag Vs TempData.

    TempData, is also a dictionary which is based on the TempDataDictionary class. It keeps the information temporarily, as long as the HTTP request is active. TempData is perfect for redirection and few other instances because of its temporary nature.

    ViewBag is defined as to pass data from Controller Action to view to render the data that is being passed. Now we can pass data between Controller Action and View either by using ViewBag or ViewData.  

    ViewBag: It is type of Dynamic object, which means we can add new fields to viewbag dynamically and access these fields in the View. We need to initialize the object of viewbag at the time of creating new fields.