---
title: "Difference between View bag,View data and Temp data"  
description: "Difference between View bag,View data and Temp data"  
author: "Manish Kumar"  
published: 2017-03-08  
updated: 2020-09-19  
canonical: https://www.mindstick.com/interview/23228/difference-between-view-bag-view-data-and-temp-data  
category: "c#"  
tags: ["mvc4"]  
reading_time: 2 minutes  

---

# Difference between View bag,View data and Temp data

**View Bag-**

View Bag is use to pass data from controller to view not vice versa . it is valid only at the current request only.

If redirection occurs its value will be null.

It doesn’t require typecasting.

View Bag is the dynamic property of ControllerBase class.

## View Data –

View Data is use to pass data from controller to view in the current request only but not vice versa.

It uses string as key.

If redirection occurs it value will be null.

It requires Typecasting.

## Temp data-

Temp data is use to pass data from one action to another of the same or different controller.

It retains the value after redirection.

## Answers

### Answer by Manish Kumar

**View Bag-**

View Bag is use to pass data from controller to view not vice versa . it is valid only at the current request only.

If redirection occurs its value will be null.

It doesn’t require typecasting.

View Bag is the dynamic property of ControllerBase class.

## View Data –

View Data is use to pass data from controller to view in the current request only but not vice versa.

It uses string as key.

If redirection occurs it value will be null.

It requires Typecasting.

## Temp data-

Temp data is use to pass data from one action to another of the same or different controller.

It retains the value after redirection.


---

Original Source: https://www.mindstick.com/interview/23228/difference-between-view-bag-view-data-and-temp-data

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
