How does the ASP.NET MVC\'s ViewBag
work? MSDN says it is just an Object
, which intrigues me, how does \"Magic\" properties such as ViewBag.F
ViewBag is used to pass data from Controller Action to view to render the data that being passed. Now you can pass data using between Controller Action and View either by using ViewBag or ViewData. ViewBag: It is type of Dynamic object, that means you can add new fields to viewbag dynamically and access these fields in the View. You need to initialize the object of viewbag at the time of creating new fields.
e.g: 1. Creating ViewBag: ViewBag.FirstName="John";