Blog coding and discussion of coding about JavaScript, PHP, CGI, general web building etc.

Sunday, December 13, 2015

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

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:

  

-- 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 by reaper_unique for The controller for path was not found or does not implement IController


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.

Answer by Carlos Martinez for The controller for path was not found or does not implement IController


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 pointin 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:

False

Answer by armulator for The controller for path was not found or does not implement IController


Here is my problem and the solution that what worked for me.

I added a new controller with a single action returning a string to an existing application. But when I navigated to that controller via browser, I was getting the same error as mentioned above.

After doing lot of googling, I found out that I simply had to modify my Global.asax.cs file for it to recognize the new controller. All I did was added a space to Global.asax.cs file so that it is modified and it worked

Answer by Tejasvi Hegde for The controller for path was not found or does not implement IController


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 :)

Answer by George Stocker for The controller for path was not found or does not implement IController


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.

Answer by Richard Freeman for The controller for path was not found or does not implement IController


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:

Areas.{AreaName}.Controller  

fixed the issue for me.

I suspect the key factor was to have all the controllers within a given area share the same namespace.

Answer by SoaperPlus for The controller for path was not found or does not implement IController


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  

Answer by Carl for The controller for path was not found or does not implement IController


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.

Answer by Mike Smith for The controller for path was not found or does not implement IController


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.


Fatal error: Call to a member function getElementsByTagName() on a non-object in D:\XAMPP INSTALLASTION\xampp\htdocs\endunpratama9i\www-stackoverflow-info-proses.php on line 71

0 comments:

Post a Comment

Popular Posts

Powered by Blogger.