---
title: "What is difference between ViewData, ViewBag and TempData?"  
description: "What is difference between ViewData, ViewBag and TempData?"  
author: "Hemant Patel"  
published: 2017-12-14  
updated: 2020-09-21  
canonical: https://www.mindstick.com/interview/23328/what-is-difference-between-viewdata-viewbag-and-tempdata  
category: "c#"  
tags: ["c#", "asp.net mvc", "mvc", "mvc4", "viewbag", "tempdata", "viewdata"]  
reading_time: 1 minute  

---

# What is difference between ViewData, ViewBag and TempData?

ViewData and ViewBag are almost similar,and TempData carry out additional responsibility.

The main difference between ViewBag and ViewData is, ViewBag is a dynamic property that takes benefit of the new dynamic features in C# 4.0. And ViewData is a dictionary of objects that is derived from ViewDataDictionary class and is attainable using strings as keys.

Now we Discuss about TempData,

TempData helps to maintain data when you move from one controller to other controller or from one action to other action. TempData internally uses session variables.

## Answers

### Answer by Hemant Patel

ViewData and ViewBag are almost similar,and TempData carry out additional responsibility.

The main difference between ViewBag and ViewData is, ViewBag is a dynamic property that takes benefit of the new dynamic features in C# 4.0. And ViewData is a dictionary of objects that is derived from ViewDataDictionary class and is attainable using strings as keys.

Now we Discuss about TempData,

TempData helps to maintain data when you move from one controller to other controller or from one action to other action. TempData internally uses session variables.


---

Original Source: https://www.mindstick.com/interview/23328/what-is-difference-between-viewdata-viewbag-and-tempdata

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
