我有 2 条不同的路线:
context.MapRoute(
"zyzzyva_default",
"{urlTitle}",
new { area = "zyzzyva", action = "Index", controller = "Home", urlTitle = UrlParameter.Optional }
);
第二个:
context.MapRoute(
"Vip_default_vip_thankyou",
"{partnername}-vip-thank-you",
new { controller = "Vip", action = "ThankYou", partnername = "" },
new string[] { "Web.Areas.Vip.Controllers" }
);
当我访问 mydomain.com/aaaa-vip-thank-you
时,它应该使用第二条路由,但我不明白为什么它使用第一条路由。
最佳答案
第一条路线太笼统了。
路由按照注册顺序找到第一个匹配项。
更改映射顺序。
context.MapRoute(
"Vip_default_vip_thankyou",
"{partnername}-vip-thank-you",
new { controller = "Vip", action = "ThankYou", partnername = "" },
new string[] { "Web.Areas.Vip.Controllers" }
);
context.MapRoute(
"zyzzyva_default",
"{urlTitle}",
new { area = "zyzzyva", action = "Index", controller = "Home",urlTitle = UrlParameter.Optional }
);
关于c# - ASP.NET MVC 路由不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39978432/