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.
Liked By
Write Answer
ViewBag Vs TempData.
Join MindStick Community
You have need login or register for voting of answers or question.
Nishi Tiwari
29-Jan-2020TempData, 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.