| What is ViewData in MVC
ViewData is similar to ViewBag. Which is useful in transferring data from Controller to View. ViewData have the key, value pairs as dictionary which drived from class "ViewDataDictionary". Its transfers data from controller to view but not vice-versa. And its valid only during the current request. In action method we setting the value for ViewData and in view the value will be fetched by typecasting.
ViewData only lasts during current http request. ViewData values will be cleared if redirection occurs.
ViewData value must be type cast before use. | | |