---
title: "What is the difference between tempdata, viewdata, and viewbag?"  
description: "What is the difference between tempdata, viewdata, and viewbag?"  
author: "Anonymous User"  
published: 2019-10-15  
updated: 2019-10-15  
canonical: https://www.mindstick.com/forum/105421/what-is-the-difference-between-tempdata-viewdata-and-viewbag  
category: "asp.net mvc"  
tags: ["c#", "asp.net mvc", "mvc", "mvc5"]  
reading_time: 2 minutes  

---

# What is the difference between tempdata, viewdata, and viewbag?

[Difference between tempdata, viewdata, and viewbag](https://www.mindstick.com/interview/22978/what-is-difference-between-tempdata-viewdata-and-viewbag).

## Replies

### Reply by Anonymous User

**Temp data** - It helps to maintain data when you move from one controller to another controller or from one action to another action. In other words when you redirect, [tempdata](https://www.mindstick.com/forum/155741/define-tempdata-in-mvc) helps to maintain data between those redirects. It internally uses session variables.

**View data** - These helps to maintain data when you move from controller to view.

**View Bag** - This is a dynamic wrapper around view data. When you use Viewbag type, casting is not required. It uses the dynamic keyword internally.

## Dynamic Keyword

**Session variables** - With the help of session variables we can maintain data from any entity to any entity.

**Hidden fields and HTML controls** - These helps to maintain data from UI to controller only. So you can send data from HTML controls or hidden fields to the controller using POST or GET HTTP methods.

Here, below this is a summary table that shows the different mechanisms for persistence.

| **Maintains data between** \ | **[ViewData](https://www.mindstick.com/forum/12798/there-is-no-viewdata-item-of-type-ienumerable-selectlistitem-that-has-the-key-username)/ViewBag** \ | **TempData** \ | **Hidden fields** | **Session** \ |
| --- | --- | --- | --- | --- |
| Controller to Controller \ | No \ | Yes \ | No\ | Yes \ |
| Controller to View \ | Yes \ | No \ | No \ | Yes \ |
| View to Controller | No | No | Yes \ | Yes |
| \ | \ | \ | \ | \ |


---

Original Source: https://www.mindstick.com/forum/105421/what-is-the-difference-between-tempdata-viewdata-and-viewbag

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
