我有路线
routes.MapRoute(
name: "Default",
url: "{langCode}/{controller}/{action}",
defaults: new { controller = "Services", action = "Index", langCode = "en" }
);
有没有办法链接到每个添加的langCode? 我不想添加像这样的每个链接
routeValues: new { langCode = ViewContext.RouteData.Values["langCode"] }
PS:
@Html.ActionLink("Log in", "Login", "Account", routeValues: new { langCode = ViewContext.RouteData.Values["langCode"] })
答案 0 :(得分:0)
你不需要每次都写:
@Html.ActionLink("Log in", "Login", "Account", routeValues: new { langCode = ViewContext.RouteData.Values["langCode"] })
如果当前url中存在langCode路由值,那么框架本身将自动重用它。例如,如果当前网址看起来像/en/Account/Register
而您拨打@Html.ActionLink("Log in", "Login", "Account")
,则生成的网址将为/en/Account/Login