The ViewData dictionary created by the controller (more precisely, the first time you open it) is freed up after the rendering is complete. Getter excerpt:
public ViewDataDictionary ViewData { get { if (this._viewDataDictionary == null) { this._viewDataDictionary = new ViewDataDictionary(); } return this._viewDataDictionary; } set { this._viewDataDictionary = value; } }
In principle, you can assume that ViewData will be available from the very beginning of the request inside your controller by rendering the view itself, and it will be released after the page finishes rendering.
source share