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.
Join MindStick Community
You need to log in or register to vote on answers or questions.
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
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.