The controller for path was not found or does not

2019-01-10 09:02发布

I have an MVC4 project with language selection:

  • en
  • nl
  • fr
  • de

1 main part with:

  • About
  • Common (for the menu)
  • Contact
  • Faq
  • Home

And 3 areas:

  • Admin
  • Customers
  • Shop

In each area I have at least one controller, for example in Admin I have the controller overview with the corresponding view folder overview which contains an index.aspx page.

The home page and all the main pages (about, faq, etc.) work and can be visited).

However, when I follow the url: localhost:xxxx/en/admin/overview I get the error

The controller for path '/en/admin/overview' was not found or does not implement IController.

Even though, the route is correct (I can see this with Route Debugger). THe error page also shows that the error was thrown when I wanted to load my main menu items:

<nav id="site-navigation" class="eightcol">
    @Html.Action("MenuItems", "Common")
</nav>

-- Code removed because irrelevant --

Everything seems to be in order, but MVC doesn't seem to be able to load the menu, which is located in the main part.

So, the root of the problem is: Can I grant an area (e.g. Admin) access to the controllers in the main part (home, common, about, etc.) of my project?

17条回答
forever°为你锁心
2楼-- · 2019-01-10 09:40

In another scenario just I would like to add is In my scenario, the name space was different for controller as it was mistake of copying controller from another project.

查看更多
迷人小祖宗
3楼-- · 2019-01-10 09:44

Also, for those who the solution above didn't work, here's is what worked for me:

I have a solution with multiple projects. All projects were in MVC3. I installed Visual Studio 2012 in my machine and it seems that some projects were automatically upgraded to MVC4.

I got this problem

The controller for path '/etc/etc' was not found or does not implement IController

because the project that handled that route was pointing to MVC4.

I had to manually update their references to use MVC3. You can also do that by opening the .csproj file with a text editor. Find the reference to MVC3 and remove this line:

<SpecificVersion>False</SpecificVersion>
查看更多
The star\"
4楼-- · 2019-01-10 09:44

in my case, the problem was that the controller class has not been publicly announced.

class WorkPlaceController : Controller

the solution was

public class WorkPlaceController : Controller
查看更多
唯我独甜
5楼-- · 2019-01-10 09:45

This error can also be caused by the fact that Controllers must have (in their name) the word Controller; viz: HomeController; unless you implement your own ControllerFactory.

查看更多
Summer. ? 凉城
6楼-- · 2019-01-10 09:45

In my case I had @{ Html.RenderAction("HeaderMenu", "Layout", new { Area = string.Empty }); } in _Layout.cshtml but the LayoutController did not exist! (I had copied _Layout.cshtml from another solution but forgot to copy the controller)

查看更多
We Are One
7楼-- · 2019-01-10 09:45

In my case of legacy application, the issue occurred when I added below entry in web.config file under the node <system.webServer>

       <modules runAllManagedModulesForAllRequests="true"></modules>

When I removed it, the issue resolved.

查看更多
登录 后发表回答