Where are the ViewData and ViewBag located?

Note. This is not a duplicate of this question as it does not fully answer the question.

My question is where exactly is it stored when you assign a value ViewData

or ViewBag

for example TempData

in a session.

Are both also in Session

?

If not, then where?

+3


source to share


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







All Articles