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?
Not sure if this hits the solution from a different angle to the accepted answer, but I found that one of my controllers in the Areas section was sitting in the wrong namespace. Correcting the namespace to:
fixed the issue for me.
I suspect the key factor was to have all the controllers within a given area share the same namespace.
Yet another possible root cause for this error is if the namespace for the area registration class does not match the namespace for the controller.
E.g. correct naming on controller class:
With incorrect naming on area registration class:
(Namespace above should be
MySystem.Areas.Customers
.)Will I ever learn to stop copy and pasting code? Probably not.
If appropriate to your design, you can make sure the access modifier on your controller class is 'public', not something that could limit access like 'internal' or 'private'.
This problem also occurs if you don't include your controller class for compile-process in the .csproj files.
One other cause of this error: Accidental use of Html.Action in a Layout file where Html.ActionLink may have been intended. If the view referenced by the Html.Action uses the same Layout file you effectively have created an endless loop. (The layout view loads the referenced view as partial view which then loads the layout view which loads the referenced view...) If you set a breakpoint in the Layout file and single step through the Htlm.Action you will sometimes get a more helpful message about excessive stack size.
Embarrassingly, the problem in my case is that I haven't rebuilt the code after adding the controller.
So maybe the first thing to check is that your controller was built and is present (and public) in the binaries. It might save you few minutes of debugging if you're like me.