---
title: "What is difference between tempdata, viewdata, and viewbag?"  
description: "What is difference between tempdata, viewdata, and viewbag?"  
author: "Anupam Mishra"  
published: 2016-02-04  
updated: 2020-09-24  
canonical: https://www.mindstick.com/interview/22978/what-is-difference-between-tempdata-viewdata-and-viewbag  
category: "asp.net"  
tags: ["c#", "asp.net", "asp.net mvc"]  
reading_time: 2 minutes  

---

# What is difference between tempdata, viewdata, and viewbag?

**Temp data -** Helps to maintain data when we move from one controller to another controller or from one action to another action. In other words when we redirect, tempdata helps to maintain data between those redirects. It internally uses session variables.**View data -** Helps to maintain data when we move from controller to view.**View Bag -** It’s a dynamic wrapper around view data. When we use Viewbag type, casting is not required. It uses the dynamic keyword internally.Session variables - By using session variables we can maintain data from any entity to any entity.**Hidden fields and HTML controls -** Helps to maintain data from UI to controller only. So we can send data from HTML controls or hidden fields to the controller using POST or GET HTTP methods.

## Answers

### Answer by Anupam Mishra

**Temp data -** Helps to maintain data when we move from one controller to another controller or from one action to another action. In other words when we redirect, tempdata helps to maintain data between those redirects. It internally uses session variables.**View data -** Helps to maintain data when we move from controller to view.**View Bag -** It’s a dynamic wrapper around view data. When we use Viewbag type, casting is not required. It uses the dynamic keyword internally.Session variables - By using session variables we can maintain data from any entity to any entity.**Hidden fields and HTML controls -** Helps to maintain data from UI to controller only. So we can send data from HTML controls or hidden fields to the controller using POST or GET HTTP methods.


---

Original Source: https://www.mindstick.com/interview/22978/what-is-difference-between-tempdata-viewdata-and-viewbag

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
