Difference between View bag,View data and Temp data Manish Kumar150808-Mar-2017c#mvc4 Updated on 19-Sep-2020
Manish Kumar
08-Mar-2017View 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.