How to send data from Controller to View
What is the use of ViewData in Asp.Net MVC?
1676
18-Dec-2019
Updated on 18-Dec-2019
Shikhar Arora
18-Dec-2019ViewData is used to pass data from controller to view and it consist of a null value when redirection occurs. ViewData is derived from ViewDataDictionary which is dictionary type and ViewData required typecasting. Following is the code scrap of ViewData in MVC
ViewData is a dictionary object that is derived from the ViewDataDictionary class. We will see how we can assign value to ViewData in Controller with a simple example for that create one new controller in the application and write code like as shown below
Now we will create one view to show data for that right click on controller Ă select add view give the name for that view (Index.cshtml). Open view file and write the following code to show data in the website