---
title: "ViewBag Vs TempData."  
description: "ViewBag Vs TempData."  
author: "Nishi Tiwari"  
published: 2020-01-29  
updated: 2020-09-23  
canonical: https://www.mindstick.com/interview/33683/viewbag-vs-tempdata  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# 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.

## Answers

### Answer by Nishi Tiwari

**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.


---

Original Source: https://www.mindstick.com/interview/33683/viewbag-vs-tempdata

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
