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

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

问题描述

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

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

有关帐户请求发现下列匹配的控制器:
   uqs.Controllers.Admin.AccountController
   MvcApplication1.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
 );

但是这并没有解决这个问题。

but that didn't solve it.

多种类型中发现的匹配
  控制器命名为帐户。

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

我怎样才能解决这个问题呢?

How I can fix this problem?

推荐答案

您不能有多个控制器名为帐户在应用程序中,甚至在不同的命名空间。

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

您必须有这些控制器通过。(在ASP.NET MVC 2的特征)

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

如果您进行查找的AccountController 你会发现帐户在应用程序命名所有的控制器;然后将它们移动扎进不同的领域如果你想他们两个,或删除一个。

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天全站免登陆