ASP.NET MVC 2 中具有一个名称的多个控制器 [英] Multiple Controllers with one Name in ASP.NET MVC 2

查看:20
本文介绍了ASP.NET MVC 2 中具有一个名称的多个控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试运行 ASP.NET MVC 应用程序时收到以下错误:

I receive the following error when trying to run my ASP.NET MVC application:

对帐户"的请求已找到以下匹配的控制器:uqs.Controllers.Admin.AccountControllerMvcApplication1.Controllers.AccountController

The request for 'Account' has found the following matching controllers: uqs.Controllers.Admin.AccountController MvcApplication1.Controllers.AccountController

我在项目中搜索了 MvcApplication1.Controllers.AccountController 以将其删除,但找不到匹配项.

I searched the project for MvcApplication1.Controllers.AccountController to remove it, but I can't find a match.

我尝试注册一个路由来修复它:

I try to registered a route to fix it:

 routes.MapRoute(
     "LogAccount", // Route name
     "{controller}/{action}/{id}", // URL with parameters
     new { controller = "Account", action = "LogOn", id = "" },
     new string[] { "uqs.Controllers.Admin" } // Parameter defaults
 );

但这并没有解决问题.

找到多个匹配的类型名为帐户"的控制器.

Multiple types were found that match the controller named 'Account'.

我该如何解决这个问题?

How I can fix this problem?

推荐答案

即使在不同的命名空间中,您的应用程序中也不能有多个名为 Account 的控制器.

You can't have more than one controller named Account in your application, even in different namespaces.

您必须将这些控制器按 Area(ASP.NET MVC 2 中的一项功能)分开.

You have to have these controllers split up by Area (a feature in ASP.NET MVC 2).

如果您对 AccountController 进行查找,您将在您的应用程序中找到所有名为 Account 的控制器;如果你想要两个,然后将它们移到不同的区域,或者删除一个.

If you conduct a Find for AccountController you'll find all controllers named Account in your application; and move them off into different Areas if you want both of them, or delete one.

这篇关于ASP.NET MVC 2 中具有一个名称的多个控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆