Posted By : Murugan Andezuthu Dharmaratnam
Posted On : 9 December 2014
Keywords : Passing Of Data From Controller To View,Data From Controller To View,Controller To View

Passing Of Data From Controller To View

ViewData And ViewBag

This article deals with how we can pass data from a controller to view.For 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 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.



Murugan Andezuthu Dharmaratnam

Murugan is a technology leader with 14 years of hands-on experience in full life cycle systems design, development, implementation, and management. In addition to systems design and development, his core competencies include cloud design and architecture, interactive web applications and websites development, mobile computing, and Healthcare Information Technology. His experience is very diverse with a broad range of technologies within multiple industry settings including private, public, and non-profit. Coupled with his technology expertise, Murugan is a well-organized, result-oriented, and a highly analytical leader with proven track record in developing and implementing very complex systems.