Wednesday, November 23, 2011

What is difference between ViewData,ViewBag and TempData in MVC 3.0

ViewData: ViewData is a dictionary of objects that are accessible using strings as keys Eg.
1.ViewData[“JustLearn”]=”Just Learn on Beyond relational is rock!!”
ViewBag:ViewBag uses the dynamic feature that was added in to C# 4.0 It allows an object to dynamically have properties added to it. We can say viewBag=ViewData + dynamic wrapper around the ViewData dictionary. Eg.
1.ViewBag.JustLearn =”Just Learn on beyondrelational is rock!!”
TempData: Temp data use during the current and subsequent request only means it is use when you are sure that next request will be redirecting to next view. Eg.
view source
print?
1.TempData[“JustLearn”]=”Just Learn on beyondrelational is rock!!”
Hold Up

No comments:

Post a Comment