This article deals with how you can move data from a controller to view. For that you can use either ViewData or ViewBag. Let's see how you can implement it:

Step 1: Adding Controller

1. First of all, we can add a control to the project as we already seen.

2. Give name to the controller and click on Add button.

Step 2: Using ViewData

Double click on the controller and add the following contents to controller.

Step 3: Adding View

1. Add a corresponding view for the controller.

2. By Double click on the view and add the following contents to view.

3. Saving and run the application, we will obtain the result. For example, it shows the current system date and time.

Step 4: Using ViewBag

1. Likewise we can also use ViewBag instead of ViewData.Same procedure repeat again.


2. Double click on the controller and add the following contents to controller.

3. Also by Double click on the view and add the following contents to view.

4. Then run the project and it will show the current system date and time.

HostForLIFE.eu ASP.NET MVC 6 Hosting
HostForLIFE.eu is European Windows Hosting Provider which focuses on Windows Platform only. We deliver on-demand hosting solutions including Shared hosting, Reseller Hosting, Cloud Hosting, Dedicated Servers, and IT as a Service for companies of all sizes. We have customers from around the globe, spread across every continent. We serve the hosting needs of the business and professional, government and nonprofit, entertainment and personal use market segments.