Search code examples
.netcontroller

Cannot create a controller in .net 6


I tried to create a controller. But the drop-down didn't show a way to add a controller. Then I rebuild and tried. After that, I tried to startup the project. But all efforts didn't lead to solving the problem. Below I have attached how the drop-downs are displaying.

enter image description here

If further information is needed to find a solution, please let me know.


Solution

  • availability of this option depends on the project type you choose and the directory you are trying to add a controller.

    What type of project did you choose?

    In my example I created ASP.NET Core WebAPI project and got option you are looking for in any directory, but not in main project dir (if you rightclick on project). Right-click menu on the whole project.

    Right-click on one of the project directories.

    First make sure you have an appropriate project type and that you got all needed packages installed (it should be in ASP.NET package). You can install them in Visual Studio Installer by clicking modify button in your version of Visual Studio.

    You can still add this controllers as any other templates in Visual Studio, so by choosing add new item from right-click menu and choosing appropriate template: Adding controller template.