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

172,761

Solution 1

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.

Solution 2

In my case, the same error was not related to Area but thought to post the error caused in my case, which may be helpful for the people who come to this thread by searching "The controller for path was not found or does not implement IController"

The error was caused because of wrong entry in _Layout.cshtml file.

@Styles.Render("~/Content/misc")

The bundle with that name was removed in BundleConfig.cs but forgot to remove it in _Layout.cshtml

It was silly, but we programmers always do lot of silly mistakes :)

Solution 3

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:

namespace MySystem.Areas.Customers
{
    public class CustomersController : Controller
    {
        ...
    }
}

With incorrect naming on area registration class:

namespace MySystem.Areas.Shop
{
    public class CustomersAreaRegistration : AreaRegistration
    {
        ...
    }
}

(Namespace above should be MySystem.Areas.Customers.)

Will I ever learn to stop copy and pasting code? Probably not.

Solution 4

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>

Solution 5

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
Share:
172,761

Related videos on Youtube

reaper_unique
Author by

reaper_unique

IT professional

Updated on July 05, 2022

Comments

  • reaper_unique
    reaper_unique almost 2 years

    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?

    • Jonas Høgh
      Jonas Høgh over 11 years
      Have you tried commenting out the call to Html.Action to isolate the problem to the specific controller?
    • reaper_unique
      reaper_unique over 11 years
      I hadn't yet, but now I did and it's as I thought. The Area Admin uses the the layout from the main part of my project and when it reaches the Action the area tries to access the controller that isn't located in the area which throws the error. In other words, the root of the problem is, how can I grant an area access to the controllers in the main part (home, common, about, etc. controllers) of my project?
    • Alireza
      Alireza over 8 years
      The question is getting more possible problems and solutions. So it's a must, I think, to look at other answers as well and not the only the accepted one.
    • KyleMit
      KyleMit over 7 years
  • Richard Fawcett
    Richard Fawcett over 10 years
    Thanks, that worked for me. It's a very misleading error message from .NET saying that the controller for the action within the area can't be found, which isn't the case at all!
  • reaper_unique
    reaper_unique about 10 years
    Thanks for the solution. It's indeed possible that there are multiple solutions to a seemingly identical but in actuallity only a similar problem. However, as my question stated that I use areas my own selected solution is still the most accurate.
  • Jesus is Lord
    Jesus is Lord about 10 years
    Oh my gosh. That's so random and obscure. Thanks a lot for posting! :) FUTURE READERS: Mine was only slightly different - the dll version itself was 4.0 instead of 3.0 - not sure how it got changed.
  • Wilky
    Wilky over 8 years
    This was my mistake. Thanks George!
  • jbwebtech
    jbwebtech about 8 years
    We have 3 production web servers and 5 dev/test machines. Only on one production machine was it not working. Adding a space and saving Global.asax fixed it. #mindblown
  • jb007
    jb007 about 8 years
    The issue with mine was similar; I had a shared library which was referenced by the presentation layer and contained a shared controller, and the shared library was using mvc4, whereas the presentation layer was using mvc3. Once i updated the shared library to MVC3, it resolved the issue.
  • user2023861
    user2023861 over 6 years
    I had this problem. It was because I deleted my HomeController.cs file and I didn't understand what depended on it.
  • Shelby115
    Shelby115 about 6 years
    Wish you could favorite answers and not just questions. I've re-stumbled upon this answer so many times. It's been just so helpful, thanks.
  • Richard Garside
    Richard Garside about 6 years
    This caught me out and was hard to find because the namespace was wrong when it was in the root controller folder (code copied from another project), but it didn't matter before I moved it to an area.
  • Daxtron2
    Daxtron2 about 6 years
    Of course that was my problem... It's always the stupid things that get you.
  • Denys Wessels
    Denys Wessels almost 6 years
    You are the CEO
  • Darth Scitus
    Darth Scitus about 5 years
    This fixed my issue. I guess next time I should start with the green check answer instead of at the top of the list.
  • Thamarai T
    Thamarai T almost 4 years
    '@Html.Action("About", "Home", new { area = "" })' throws compilation error when specifying it as blank area. Any suggestions ?