Top Categories
Part 5 - Difference between ViewBag and Viewdata and TempData | Peak and Keep
- Category: Information Technology
- Sub Category: ASP.NET
Overview:
In this video you can practically distinguish the ViewBag , ViewData and TempData .This question is very common in every interview so be prepared for this .
It is notable if any redirection occurs then viewbag and viewdata value gets null but tempData value get preserved if and only if tem
Overview:
In this video you can practically distinguish the ViewBag , ViewData and TempData .This question is very common in every interview so be prepared for this .
It is notable if any redirection occurs then viewbag and viewdata value gets null but tempData value get preserved if and only if tempData.Keep() method is being used.
SOCIAL :
Like TechnoTips official Page : http://facebook.com/technotipstutorial
Subscribe : http://youtube.com/user/aapkanigam
Follow us on Twitter : @technotipsMVC
VISIT OUR BLOG:
http://technotipstutorial.blogspot.com
INTRODUCTION :
ViewData and ViewBag
Used to pass data from controller to corresponding view.
ViewData is a dictionary of objects that is derived from ViewDataDictionary class and is accessible using strings as keys.
ViewBag is a dynamic container.
ViewData requires typecasting for complex data type and check for null values to avoid error.
ViewBag doesn’t require typecasting for complex data type.
Ex : ViewBag.MyName=“Ashish” , ViewData[“MyName”]=“Ashish"
TempData:
TempData is also a dictionary object derived from TempDataDictionary class and stored in short lives session
It helps to maintain data when you move from one controller to other controller or from one action to other action
Ex : TempData[“MyName”]=“Ashish”
TAGS :
how to create a - website
asp. net mvc
asp.net mvc interview questions
asp .net mvc tutorial
asp. net mvc 4
asp.net mvc 5 tutorial
asp net mvc developer
asp net mvc continuous integration
asp net mvc hosting
model view controller
jquery-ajax
$ ajax jquery
jquery ajax tutorial
viewbag
$controller
$model
razor view engine
$how to get rich