我在asp.net mvc app中配置我的路由,其中有多条路由,只有第一条和最后一条路由可以工作,但是我的route.config文件中心定义的路由不起作用。以下是代码:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Doctor",
url: "admin/doctor/{action}/{id}",
defaults: new { controller = "admin", action = "AddDoctor", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Admin",
url: "admin/{action}/{id}",
defaults: new { controller = "admin", action = "Login", id = UrlParameter.Optional }
);
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
答案 0 :(得分:0)
您似乎忘记了controller
路线的Admin
部分。
您应该将其定义如下:
routes.MapRoute(
name: "Admin",
url: "admin/{controller}/{action}/{id}",
defaults: new { controller = "admin", action = "Login", id = UrlParameter.Optional }
);