Introduction
In Asp.Net MVC there are three ways to pass/store data between the controllers and views.
ViewData
- ViewData is used to pass data from the controller to the view.
- It is derived from the ViewDataDictionary class.
- It is available for the current request only.
- Requires typecasting for complex data type and checks for null values to avoid error.
- If redirection occurs, then its value becomes null.
ViewBag
- ViewBag is also used to pass data from the controller to the respective view.
- ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0.
- It is also available for the current request only.
- If redirection occurs, then its value becomes null.
- Doesn’t require typecasting for complex data types.
TempData
- TempData is derived from the TempDataDictionary class.
- TempData is used to pass data from the current request to the next request.
- It keeps the information for the time of an HTTP Request. This means only from one page to another. It helps to maintain the data when we move from one controller to another controller or from one action to another action.
- It requires typecasting for complex data types and checks for null values to avoid errors. Generally, it is used to store only one-time messages like error messages and validation messages.

Sridhar YelagandhulaPosted Feb 22, 2023, 6:38 PM
Nice clear explanation!!!!
Sandeep SiddhaparaPosted Oct 6, 2020, 12:10 AM
Very Nice Article
Kumaresan MurugesanPosted Mar 8, 2020, 8:47 AM
Nice Article
satyesh soniPosted Nov 14, 2017, 1:08 AM
Nice articles.....
Gopaiah NekarukantiPosted Aug 19, 2017, 2:59 AM
Nice information.....
Dhaval RathodPosted Apr 20, 2017, 3:04 AM
Very helpful for beginners !!
kalu singh raoPosted Jul 8, 2016, 1:59 PM
Nice...
manish nainPosted May 30, 2016, 7:59 AM
www.stucorner.com
sakthi sudhanPosted Mar 24, 2016, 4:43 AM
good
Santhakumar MunuswamyPosted Apr 25, 2015, 7:18 AM
Good
Rohit ChoudharyPosted Apr 25, 2015, 6:42 AM
<html>
Rasmiranjan sahooPosted Apr 6, 2015, 8:24 AM
Nice post.