Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the scope of ViewData Dictionary?

Tags:

asp.net-mvc

What is the scope of ViewData Dictionary?I mean when It Creates for a View & when it destroys?

Lifecycle of ViewDataDictionary.

like image 221
SAHIL SINGLA Avatar asked May 05 '10 12:05

SAHIL SINGLA


People also ask

Is Viewdata a dictionary or a dictionary?

Since ViewData is a dictionary, it contains key-value pairs where each key must be a string. ViewData only transfers data from controller to view, not vice-versa.

What is viewdatadictionary in MVC framework?

As you can see, the ViewDataDictionary class implements the IDictionary interface. So we can say that the ViewData in ASP.NET MVC Framework is a dictionary object.

What is the use of Viewdata in Android?

ViewData is a dictionary of objects that are stored and retrieved using strings as keys. It is used to transfer data from Controller to View. Since ViewData is a dictionary, it contains key-value pairs where each key must be a string.

What is the use of Viewdata in C sharp?

Csharp Server Side Programming Programming ViewData is a dictionary of objects that are stored and retrieved using strings as keys. It is used to transfer data from Controller to View. Since ViewData is a dictionary, it contains key-value pairs where each key must be a string.


1 Answers

The ViewData dictionary is created by the controller (more precisely the first time you access it) is released after the view finished rendering. Excerpt from the getter:

public ViewDataDictionary ViewData
{
    get
    {
        if (this._viewDataDictionary == null)
        {
            this._viewDataDictionary = new ViewDataDictionary();
        }
        return this._viewDataDictionary;
    }
    set
    {
        this._viewDataDictionary = value;
    }
}

Basically you may assume that the ViewData will be accessible from the beginning of the request inside you controller through the rendering of the view itself and it will be released after the page has finished rendering.

like image 163
Darin Dimitrov Avatar answered Nov 18 '22 21:11

Darin Dimitrov