What is ViewData in MVC
What is ViewData in MVC?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Nilesh JadavPosted Oct 12, 2015, 9:31 AM
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 !
Priyaranjan K SPosted Oct 12, 2015, 12:47 PM
Sujeet SumanPosted Oct 12, 2015, 12:34 PM
Ravi PatelPosted Oct 12, 2015, 9:32 AM
public ActionResult Index(){return View();and in View page