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

落爺英雄遲暮 提交于 2020-05-28 12:02:21

问题


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

Following gives 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.


回答1:


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.




回答2:


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




回答3:


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.




回答4:


I had this exact scenario when my controller file name did not match the controller class name:

I had a controller class named InvoicesController, but the file name was InvoiceController.cs. After renaming the file name to the class name of the controller the switching back from the view to the controller started working




回答5:


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.



来源:https://stackoverflow.com/questions/40473899/go-to-controller-shows-unable-to-find-a-matching-controller-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!