我注册了两条路线:
//News page routing with optional news article ID
routes.MapRoute(
name: "News",
url: "news/{id}",
defaults: new { controller = "News", action = "Index", id = UrlParameter.Optional }
);
默认链接(无 id)生成为:@Html.ActionLink("News", "Index", "News")
和
//User page routing with User ID
routes.MapRoute(
name: "Profile",
url: "{id}/{controller}/{action}",
defaults: new { controller = "Account", action = "Index", id = UrlParameter.Optional }
);
链接生成为:
[a href="@Url.Action("Index", "Account", new RouteValueDictionary(new { id = "test-user-id" }))"]Me[/a]
到目前为止一切都很好,我的新闻链接创建为域/新闻并且有效,我的链接创建为域/测试用户 ID 并且也有效。
但是一旦我访问 Me 链接,News 链接就变成了 domain/news/test-user-id,这不是我想要的。如何使用 mvc 路由“分离”新闻 id 和用户 id?