Reputation: 1365
In the MSDN documentation, there are ViewBag.MyMessageToUsers
and ViewBag.AnswerText
. In the ASP.net/mvc tutorial, there are ViewBag.Message
, ViewBag.NumTimes
and such. What are the data types of these properties? And where in the solution are they declared?
Upvotes: 1
Views: 194
Reputation: 157
What are the data types of these properties?
Answer: There is no type for ViewBag! It is just like a Bag and you can put lots of stuff in it.
Where in the solution are they declared?
Answer: You could declare the type when you want use your data inside the ViewBag with converting to types.
Upvotes: -1
Reputation: 2822
ViewBag is a dynamic collection. In your controller you can put whatever you want in it and call it from your View. They can be whatever objects and whatever types you want.
The link you provided to the MSDN Documentation is providing an example of this.
If you have the following in your controller:
ViewBag.Something = thing;
thing
is declared somewhere, and you are accessing it here. You don't declare ViewBag
, and Something
gets automatically declared when you assign thing
to it.
Upvotes: 5