Add a controller

Adding Controller in Visual Studio

The MVC project contains folders for the Controllers and Views, follow the steps shown below

In Solution Explorer, right-click Controllers > Add > Controller.

Solution Explorer, right click Controllers > Add > Controller

In the Add New Scaffolded Item dialog box, select MVC Controller - Empty > Add.

Add MVC controller

In the Add New Item - MvcMovie dialog, enter HelloWorldController.cs and select Add.

Replace the contents of Controllers/HelloWorldController.cs with the following code:

Every public method in a controller is callable as an HTTP endpoint. Note the comments preceding each method.

Last updated