ASP.NET MVC 2 Preview 2:区域重复控制器问题 [英] ASP.NET MVC 2 Preview 2: Areas duplicate controller problem

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

问题描述

我继续奴役 MVC 2 事物:区域...

现在我在主控制器文件夹和其中一个区域中有两个同名的控制器 (HomeController).两者都有不同的命名空间,所以......理论上应该共存,但他们没有.错误是:

<块引用>

控制器名称Home"在以下类型之间不明确:

Namespace.HomeController

Namespace.Areas.AreaName.Controllers.HomeController

这不仅仅与 Home 控制器有关(特殊的?),而是适用于任何领域的任何一对.

如何实现不同区域内的同名控制器共存?

感谢您的时间:)

在不同区域内使用相同的控制器名称是可以的:使用命名空间注册路由解决了这个问题(感谢 Scott 的 Allen 文章 ).

解决方案

如果两个类名相同的控制器在两个不同的区域,这会正常工作.

就您而言,您在一个区域中有一个控制器,在默认控制器文件夹"中有一个控制器.你确定这是你想要的吗?您的默认控制器文件夹"是否应该包含某种共享控制器,例如默认帐户控制器?

这实际上是一个 ASP.NET 路由问题,而不是命名空间或类名问题.问题很可能是你有两条路由到不明确的控制器名称;一个通过区域注册注册,一个通过RegisterRoutes中的默认路由注册.

另外,请参阅这篇关于区域排序的帖子.>

I am continuing to enslave the MVC 2 thing: Areas...

Now I have two controllers with the same name (HomeController) in the main Controllers folder and in one of the Areas. Both have different namespaces so... theoretically should coexists, but they don't. The error is:

The controller name 'Home' is ambiguous between the following types:

Namespace.HomeController

Namespace.Areas.AreaName.Controllers.HomeController

This is not related to Home controller only (special one?), but applies to any pair in any areas.

How to achieve the coexistence of the same-name-controllers within different areas?

Thanks for your time :)

EDIT: It is okay for same controller name WITHIN different areas: registering routing with namespace solves the problem (thanks to Scott's Allen article ).

解决方案

If the two controllers with the same class name are in two different areas, this works as expected.

In your case, you have one controller in an area, and one controller in the "default Controllers folder". Are you sure this is what you want? Is your "default Controllers folder" supposed to contain some kind of shared controllers, such as the default account controller?

This is really an ASP.NET Routing issue as opposed to a namespace or class name issue. The problem is most likely that you have two routes to the ambiguous controller name; one registered via area registration and one via the default route registration in RegisterRoutes.

Also, see this post about area ordering.

这篇关于ASP.NET MVC 2 Preview 2:区域重复控制器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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