Gets the dynamic view data dictionary.
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
The ViewBag property enables you to dynamically share values from the controller to the view. It is a dynamic object which means it has no pre-defined properties. You define the properties you want the ViewBag to have by simply adding them to the property. In the view, you retrieve those values by using same name for the property.
The following example shows how to create two properties for the ViewBag in a controller.
The next example shows how to retrieve those ViewBag properties from your view. The first line displays the value of the MyMessageToUsers property as text. The second line creates a text box and pre-populates it with the value of the AnswerText property.