0% found this document useful (0 votes)
26 views5 pages

Passing Data with ViewData and ViewBag

The document discusses how to pass data from a controller to a view in MVC using ViewData and ViewBag. It explains adding a controller and view, then using ViewData in the controller to add data and display it in the view. Alternatively, it describes using ViewBag in the same way to pass and display data between the controller and view, such as the current system date and time.

Uploaded by

Ranjith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views5 pages

Passing Data with ViewData and ViewBag

The document discusses how to pass data from a controller to a view in MVC using ViewData and ViewBag. It explains adding a controller and view, then using ViewData in the controller to add data and display it in the view. Alternatively, it describes using ViewBag in the same way to pass and display data between the controller and view, such as the current system date and time.

Uploaded by

Ranjith
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Passing Of Data From Controller To View

ViewData And ViewBag

This article deals with how we can pass data from a controller to [Link] that we can use either
ViewData or ViewBag.
Let us see how we can implement it...

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.


Using ViewData

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

Adding View

Add a corresponding view for the controller.


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

2. Saving and run the application, we will obtain the result. ie, it shows the current system date
and time.
Using ViewBag

1. Likewise we can also use ViewBag instead of [Link] 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.

You might also like