reaper_unique reaper_unique - 15 days ago 5
C# Question

The controller for path was not found or does not implement IController

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?

Answer

I've found it.

When a page, that is located inside an area, wants to access a controller that is located outside of this area (such as a shared layout page or a certain page inside a different area), the area of this controller needs to be added. Since the common controller is not in a specific area but part of the main project, you have to leave area empty:

@Html.Action("MenuItems", "Common", new {area="" }) 

The above needs to be added to all of the actions and actionlinks since the layout page is shared throughout the various areas.

It's exactly the same problem as here: ASP.NET MVC Areas with shared layout

Edit: To be clear, this is marked as the answer because it was the answer for my problem. The above answers might solve the causes that trigger the same error.

Comments