Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Go To Controller shows "Unable to find a matching controller." error

In VS 2015, for my Web.API project, I installed MVC 5 from nuget via npm. This installation added references and generated web.config file under Views folder.

I added new Controller with generated CRUD functions. When I right click and go to View on action it goes with no problem. But reverse action does not work. If I navigate to view via browser it works as well. Web app compiles as well.

Is there any way for me to fix this navigation problem in VS? Did I forget to add something?

Following Works

this works with no problem

Following gives Error:

this does not work

error

P.S: If I create brand new sample MVC 5 app both actions work as expected, this only happens Web.API project where MVC 5 added later on via nuget.

like image 466
Teoman shipahi Avatar asked Nov 07 '16 20:11

Teoman shipahi


4 Answers

This happened to me once. Delete the view and try adding the view again by right clicking on the controller action method and clicking Add View again. I think it would solve the problem

like image 76
Sharthak Ghosh Avatar answered Nov 01 '22 10:11

Sharthak Ghosh


It happens while the controller or view may be not exactly in the controller folder or view folder respectively. It may contain an additional folder. You can solve this issue through adding a new view and delete the old view.

like image 4
Alsamil Mehboob Avatar answered Nov 01 '22 12:11

Alsamil Mehboob


There appears to be a default shortcut key Ctrl-M then Ctrl-G.

This will automatically switch between the controller and view page. If you're on the controller/action it will switch to the view and vice versa.

like image 4
VIGNESH ARUNACHALAM Avatar answered Nov 01 '22 12:11

VIGNESH ARUNACHALAM


My situation is not exactly the same as your (I added a new controller and new view), but I was receiving the same error message. Ensure that the name of your controller matches the name of the folder that the view is in.

For example, if the controller is TodoController.cs ensure that the view is in a folder called Todo. It doesn't seem to matter what the view .cshtml file is called. That's what fixed it for me.

like image 3
Brendan L Avatar answered Nov 01 '22 12:11

Brendan L