开发者

Controllers in seperate assembly and getting a 'The controller for path "/controllerName/" was not found or does not implement IController.' error

I am doing some work on a project and I am trying to get my development environment working. The project is written in ASP.net MVC 2. I have ASP.net MVC 3 installed. The controllers have been moved to a seperate project that is namespaced ProjectName.Web.Controllers. All of the controllers inherit from System.Web.MVC.Controller. When I try to hit a controller I get the following:

[HttpException]: The controller for path '/controllerName'; was not found or does not implement IController.

If I make a controllers folder in the web project that contains the views, copy all the controlle开发者_StackOverflow社区rs there and recompile, it works fine.


You need to add the new project namespace into the DefaultNamespaces collection on the current ControllerBuilder

ControllerBuilder.Current.DefaultNamespaces.Add("ProjectName.Web.Controllers");


You said that you moved all the controllers in a separate project. Did you reference this project in your ASP.NET MVC application? Is the resulting assembly present in the bin folder of the site?


Finally figured out the problem in revisiting this today. The solution was created on a machine that did not have the latest version of ASP.Net MVC on it. It only had version 2 and worked just fine. My machine has version 3 and didn't work. Turns out the controller project was referencing the version 3 assembly on my machine and the version 2 on the original machine. The reference looked like the following:

<Reference Include="System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
      <SpecificVersion>False</SpecificVersion>
      <HintPath>..\Web\bin\System.Web.Mvc.dll</HintPath>
</Reference>

Since the web project is using version 2 of ASP.Net MVC that is why I was getting the error that the controller didn't implement IController, it was looking for IController in version 2 not version 3.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜