MVC路由映射:1个URL模式仅适用于1个控制器

时间:2012-12-06 10:55:25

标签: asp.net-mvc asp.net-mvc-routing url-routing

routes.MapRoute(
            name: "GetAdressen",
            url: "{controller}",
            defaults: new { controller = "AdressenController", action = "GetAdressen"}
        );
        routes.MapRoute(
            name: "GetEinsaetze",
            url: "{controller}",
            defaults: new { controller = "EinsaetzeController", action = "GetEinsaetze"}
        );

在这种情况下,只有/ Adressen可以使用,而不是/ Einsaetze

        routes.MapRoute(
            name: "GetEinsaetze",
            url: "{controller}",
            defaults: new { controller = "EinsaetzeController", action = "GetEinsaetze"}
        );
routes.MapRoute(
            name: "GetAdressen",
            url: "{controller}",
            defaults: new { controller = "AdressenController", action = "GetAdressen"}
        );

在这种情况下,只有/ Einsaetze可以使用,而不是/ Adressen

为什么?

1 个答案:

答案 0 :(得分:0)

像这样使用

   routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional },
                namespaces: new[] { "projectName.Controllers" });