我正在尝试在基于 ASP.NET MVC 的网站上创建一个页面,其中一个页面允许通过用户名而不是 ID 进行选择。我会认为路线需要是这样的:
routes.MapRoute(
"CustomerView", "Customer/Details/{username}",
new { username = "" }
);
routes.MapRoute(
"Default", "{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "0" }
);
但是每当我使用 HTML.Actionlink 时,我都会得到http://mysite.com/Customer/Details?username=valuehere。我考虑了一条通用路线,例如:
routes.MapRoute(
"CustomerView", "Customer/Details/{username}",
new { controller="Customer", action = "Details", username = "" }
);
但我想当它错误地应用这两者的哪条路线时会引起更多的问题。