Difference between ViewData, ViewBag, TempData and Session in MVC.

Posted by Questpond under ASP.NET MVC category on | Points: 350 | Views : 10168
In this MVC ( Model view controller) video we will try to understand what is the difference between viewdata,viewbag,tempdata and session.This is an interesting MVC interview question and below is a textual answer for the same.
Temp data: - Helps to maintain data when you move from one controller to other controller or from one action to other action. In other words when you redirect, "tempdata" helps to maintain data between those redirects. It internally uses session variables.
View data: - Helps to maintain data when you move from controller to view.
View Bag: - It's a dynamic wrapper around view data. When you use "Viewbag" type casting is not required.

Get Questpond videos on discounted price from ITFunda.com.

Comments or Responses

Posted by: Prageeth on: 4/18/2013
Thank you very much it's a great way to explain.now I have really cleared picture of ViewData,ViewBag,TempData and the Session variable.and how it process on the MVC architecture.

Login to post response