Syntax for specifying a namespace when using helper.RouteUrl

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

I get the ambiguous exception of the controller name due to the fact that it has one controller name in two different areas.

I read Phil Haack's post Ambiguous domain controller names

I cannot understand the syntax when trying to use UrlHelper (I have an extension class).

eg.

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

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

+3
source share
2 answers

, , . , ,

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

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

:

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" });
}
+1

helper.RouteUrl("ARoute", 
    new { controller = "Home", action = "Index", Area = "YourArea" });
+1

Source: https://habr.com/ru/post/1738420/


All Articles