Hi Guest

MobileUser

1 HomePage 1 Jobs 1 WalkIn 1Articles  

Cat Exam

 :) Latest Topic
AJAX
VB.NET
SQL Query
UDDI
CLASS
JavaScript Questions
SharePoint Interview
SilverLight
WCF
general knowledge
 ASP.NET
 :) Hot Jobs
 
 :) Latest Articles


  

 
Christmas Hanging


Difference between TempData, viewData and ViewBag in MVC
Question Posted on 08 May 2020

Home >> DotNet >> MVC >> Difference between TempData, viewData and ViewBag in MVC




Difference between TempData, viewData and ViewBag in MVC
Below are the main differences between Temp data, View and View Bag
TempData
(1)class name is TempDataDictionary where TempData is derived from.
(2)We generally used TempData to pass data from current request to next request.
(3)TempData will keep the information for the time of HTTP Request. This means 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.
(4)It genaraly requires typecasting for complex data types and checks for null values to avoid error.
(5)We use TempData to store only one time messages like the error messages and validation messages

ViewData
(1)Class name ViewDataDictionary where ViewData is derived from.
(2)ViewData is used to pass data from controller to view.
(3)It is only available for current request only.
(4)It requires typecasting for complex data types and checks for null value to avoid error.
(5)IF any redirection done then its values becomes null.


ViewBag
(1)It is a dynamic property which takes advantages of new dynamic

features in c# 4.0
(2)And ViewBag is used to pass data from the controller to respective view.
(3)It is same as ViewData means available for current request only.
(4)It will not requires typecasting for complex data type.
(5)If there some redirection occurs then its values becomes null.
0
0



 
 Input Your Comments Or suggestions(If Any)
 Name
 Email(optional)
 Comments


Other Important Questions
How to create Razor enable application in MVC3
Can you write down some syntax for Razor in MVC3
Basic diagram of MVC
Different MVC version with there features
Could not load type System.Web.Mvc.ViewPage in asp.net MVC2






 
Top Searches:asp net questions vb net questions sql query uddl questions class javascript Questions sharepoint interview questions and concept silverlight questions and concept wcf questions beans general knowledge ajax questions
PHP | Biztalk | Testing | SAP | HR |