我有一个必须遵循的特定文件夹结构(/ countrycode / language /)所以我的路由设置如下
routes.MapRoute(
"en-us",
"us/en/{action}/{id}",
new { Controller = "XXX", action = "Index", cc = "us", ll = "en", id = UrlParameter.Optional }
);
routes.MapRoute(
"fr-fr",
"fr/fr/{action}/{id}",
new { Controller = "XXX", action = "Index", cc = "fr", ll = "fr", id = UrlParameter.Optional }
);
routes.MapRoute(
"de-de",
"de/de/{action}/{id}",
new { Controller = "XXX", action = "Index", cc = "de", ll = "de", id = UrlParameter.Optional }
);
我在该控制器中有一个控制器和多个动作。当我尝试重定向到某个操作或链接到视图中的操作时,即使我当前位于/ fr / fr /中,该URL也始终以/ us / en /开头。
e.g。如果当前路由是/ fr / fr /
@Html.ActionLink("fooText", "fooAction")
@Url.Action("barAction")
return RedirectToRoute("Index");
所有最终都是
/us/en/fooAction
/us/en/barAction
/us/en/
如何将这些方法链接到正确的网址?
答案 0 :(得分:1)
确定而不是:
@Html.ActionLink("fooText", "fooAction")
我需要使用:
@Html.RouteLink("fooText", "fr-fr", new { controller = "XXX", action = "fooAction" })