3

I am using Asp.Net MVC 2 - RC w/ Areas.

I am receiving an ambigious controller name exception due to having same controller name in two different areas.

I've read Phil Haack's post Ambiguous Controller Names With Areas

I can't figure out the syntax when trying to use UrlHelper (I have an extensions class).

e.g.

public static string MyAreaHome(this UrlHelper helper) {
    return helper.RouteUrl("ARoute", 
        new { controller = "Home", action = "Index" });
}

I've tried the obvious of adding namespace="mynamespace" but that didn't work, it just added the namespace to the url. Thanks for any help.

Sander Rijken
  • 21,376
  • 3
  • 61
  • 85
B Z
  • 9,363
  • 16
  • 67
  • 91

2 Answers2

1

Maybe you can work around it by using two separate routes. I think this is also what Phil is trying to demonstrate in the route registration example on the 'Ambiguous Controller Names With Areas' post

routes.MapRoute(
    "ARoute",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = "" }
);

routes.MapRoute(
    "BRoute",
    "{controller}/{action}/{id}",
    new { controller = "Home", action = "Index", id = "" }
);

Then you can refer to both routes like this:

public static string MyAreaHome(this UrlHelper helper) {
    return helper.RouteUrl("ARoute", 
        new { controller = "Home", action = "Index" });
}

public static string MyOtherAreaHome(this UrlHelper helper) {
    return helper.RouteUrl("BRoute", 
        new { controller = "Home", action = "Index" });
}
Sander Rijken
  • 21,376
  • 3
  • 61
  • 85
  • This helped resolve the issue. On the "general" route I specified the namespace. In the area route, where the routes are registered I specified the area namespace and that solved the issue. – B Z Mar 25 '10 at 20:01
1

did you try

helper.RouteUrl("ARoute", 
    new { controller = "Home", action = "Index", Area = "YourArea" });
moi_meme
  • 9,180
  • 4
  • 44
  • 63