ASP.NET MVC 2 Preview 2: Problems with Duplicate Areas

I keep enslaving the MVC 2 thing: Neighborhoods ...

Now I have two controllers with the same name (HomeController) in the folder of the main controllers and in one of the areas. Both have different namespaces, therefore ... theoretically should coexist, but they do not. Mistake:

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

Namespace.HomeController

Namespace.Areas.AreaName.Controllers.HomeController

This does not apply only to the home controller (special?), But applies to any pair in any areas.

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

Thank you for your time:)

EDIT: This is normal for a single controller name. In different areas: registering routing with a namespace solves the problem (thanks to Scott Allen article ).

+6
asp.net-mvc
source share
2 answers

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

In your case, you have one controller in the area and one controller in the Default Controllers folder. Are you sure this is what you want? Is it supposed that your default controllers folder should contain some common controllers, such as the default account controller?

This is really an ASP.NET routing problem, not a namespace or class name problem. The problem is most likely that you have two paths to the ambiguous controller name; one registered through the domain registration and one through the default default registration in RegisterRoutes.

Also see this post about ordering the area .

+2
source share

If you create an application namespace, this is MvcApplication1, you wrote it.

public static void RegisterRoutes(RouteCollection routes) { routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); AreaRegistration.RegisterAllAreas(); routes.MapRoute( "Default", // Route name "{controller}/{action}/{id}", // URL with parameters new { controller = "Home", action = "Index", id = "" }, // Parameter defaults null, new[] { "MvcApplication1.Controllers" } ); } 

Set the namespace of the root route controller "MvcApplication1.Controllers", it works.

Hope these are tips.

+6
source share

All Articles