Where are the ViewData and ViewBag located?
1 answer
As @SlickSim pointed out, they are stored on the heap as reference types are in .net.
ViewBag
has a type dynamic
but internallySystem.Dynamic.ExpandoObject()
It is declared like this:
dynamic ViewBag = new System.Dynamic.ExpandoObject();
so you can:
ViewBag.Foo = "Bar";
Inheritance Hierarchy:
System.Object
System.Dynamic.ExpandoObject
More on ExpandoObject
Go through this article on Value Type, Reference Type, Heap and Stack in Code Project which can help you understand where both ViewData and Viewbag reside.
Hope this helps!
+4
source to share