This course will be retired on June 1, 2025.
Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Start a free Courses trial
to watch this video
Now that we have our project, let’s add the first controller for our Comic Book Gallery website.
Follow Along
To follow along commiting your changes to this course, you'll need to fork the aspnet-comic-book-gallery repo. Then you can clone, commit, and push your changes to your fork like this:
git clone <your-fork>
cd aspnet-comic-book-gallery
git checkout tags/v1.5 -b adding-a-controller
Controller Scaffolding
In this video, we added a controller to our project by adding a C# class using the “Add > Class...” menu item. Using this method allowed us to understand what makes a C# class an ASP.NET MVC controller. While this method works, it’s not the typical way that developers add controllers to their ASP.NET MVC projects.
Visual Studio provides a feature called “scaffolding” that can be used to quickly and easily add items to a project. You can use scaffolding to add a controller to an ASP.NET MVC project by right-clicking on the “Controllers” folder and selecting the “Add > Controller…” menu item. That’ll open up the “Add Scaffold” dialog, which will present you with a list of controller templates to choose from.
For more information on how to add a controller to an ASP.NET MVC project use Visual Studio scaffolding see http://www.asp.net/mvc/overview/getting-started/introduction/adding-a-controller.
Additional Learning
For more information on how to perform quick actions with light bulbs in Visual Studio, checkout out this MSDN page.
For more information about classes, access modifiers, and inheritance, check out these pages on MSDN.
Keyboard Shortcuts
-
CTRL+SHIFT+B
- Build solution
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up