我不知道我的路由配置有什么问题。
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
但@Url.Action("Index","Agent")
返回
而不是
请告诉我遗漏的内容:)
P.S 我不想打扰默认的路由设置,即
答案 0 :(得分:0)
在之前映射一条没有action = "Index"
的路线<&strong>&#34;默认&#34;路线:
routes.MapRoute(
name: "NoDefaultAction",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", id = UrlParameter.Optional }
);
// Code below unchanged
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
现在@Url.Action("Index", "Agent")
返回"/Agent/Index"
和&#34;默认&#34;路线不受干扰: