Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Nilesh JadavRank #109 · 20.3K reputationPosted Oct 12, 2015, 5:31 AM EDT
ViewData and ViewBag are used for the same purpose to transfer data from controller to view. Both life lies only in current request. ViewData is nothing but dictionary of object and it is accessible by string as key. ViewData is property of controller that exposes an instance of the ViewDataDictionary class. ViewBag is very similar to ViewData.
ViewBag is a dynamic property (dynamic keyword which is introduced in .net framework 4.0). ViewBag is able to set and get value dynamically and able to add any number of additional fields without converts it to strongly typed. ViewBag is just a wrapper around the ViewData.
In Asp.Net MVC there are three ways to pass/store data between the controllers and views.
ViewData
ViewBag
TempData
Thank you !
Ravi PatelRank #439 · 5.7K reputationPosted Oct 12, 2015, 5:32 AM EDT
Sujeet SumanRank #790 · 2.9K reputationPosted Oct 12, 2015, 8:34 AM EDT
Priyaranjan K SRank #45 · 32.5K reputationPosted Oct 12, 2015, 8:47 AM EDT