3

我在使用 mvc 3 和我的应用程序注册区域时遇到问题,但在应用程序启动时没有功能让我:

{System.Web.HttpException (0x80004005): The controller for path '/Login/Index' was not 
found or does not implement IController.
   at System.Web.Mvc.DefaultControllerFactory.GetControllerInstance(RequestContext requestContext, Type controllerType)
   at System.Web.Mvc.DefaultControllerFactory.CreateController(RequestContext requestContext, String controllerName)
   at System.Web.Mvc.MvcHandler.ProcessRequestInit(HttpContextBase httpContext, IController& controller, IControllerFactory& factory)
   at System.Web.Mvc.MvcHandler.<>c__DisplayClass6.<BeginProcessRequest>b__2()
   at System.Web.Mvc.SecurityUtil.<>c__DisplayClassb`1.<ProcessInApplicationTrust>b__a()
   at System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f)
   at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action)
   at System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust[TResult](Func`1 func)
   at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContextBase httpContext, AsyncCallback callback, Object state)
   at System.Web.Mvc.MvcHandler.BeginProcessRequest(HttpContext httpContext, AsyncCallback callback, Object state)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)}
4

4 回答 4

2

如果在您的 Area 的错误命名空间中声明了 Controller 类,则可能会发生此错误。确保命名空间与区域注册匹配。

于 2013-10-18T19:27:30.613 回答
1

这是一个古老的问题,但我真的无法在其他任何地方找到正确的答案。这是我的解决方案:

我有一个包含多个项目的解决方案。所有项目都在 MVC3 中。我在我的机器上安装了 Visual Studio 2012,似乎有些项目自动升级到了 MVC4。

我遇到了这个问题“ The controller for path '/etc/etc' was not found or does not implement IController”,因为处理该路由的项目指向 MVC4。

我不得不手动更新他们的引用以使用 MVC3。您也可以通过使用文本编辑器打开 .csproj 文件来做到这一点。找到对 MVC3 的引用并删除此行:

<SpecificVersion>False</SpecificVersion>

于 2013-11-01T15:16:38.423 回答
0

这意味着 MVC 无法找到实现 的类IController,无论是通过默认Controller类还是其他某种机制,也就是Index在命名空间中命名的{DefaultNamespace}.Controllers.Login

一般来说,如果您像默认的 MVC 项目结构那样构建您的 MVC 应用程序,那么您不会对这种类型的事情有任何问题。

但是,如果您使用了正确的文件夹结构并且这样说,那么Index您设置的控制器没有正确继承。

这个答案当然是假设您使用的是第一次从模板创建项目时设置的基本默认路由。

于 2013-04-15T17:49:12.297 回答
0

在我的情况下,默认路由new { controller = "Home", action = "Index", id = "" }指向错误的控制器。

全球.asax.cs

protected void Application_Start(object sender, EventArgs e)
{
    AreaRegistration.RegisterAllAreas();
    FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
    RouteConfig.RegisterRoutes(RouteTable.Routes);
    BundleConfig.RegisterBundles(BundleTable.Bundles);
}

路由配置.cs

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

        routes.MapMvcAttributeRoutes();

        routes.MapRoute(
            "Default",
            "{controller}/{action}/{id}",
            new { controller = "Home", action = "Index", id = "" }
        );
    }
}
于 2020-01-02T14:29:04.670 回答