我在“使用条款”页面的几个翻译的顶部都有这个:
<li><a href="@Url.Action("Index", "Terms")">English</a></li>
<li><a href="@Url.Action("Index", "Terms", "de")">Deutsch</a></li>
<li><a href="@Url.Action("Index", "Terms", "fr")">Français</a></li>
<li><a href="@Url.Action("Index", "Terms", "it")">Italiano</a></li>
<li><a href="@Url.Action("Index", "Terms", "nl")">Nederlands</a></li>
<li><a href="@Url.Action("Index", "Terms", "hu")">Maygar</a></li>
<li><a href="@Url.Action("Index", "Terms", "es")">Español</a></li>
<li><a href="@Url.Action("Index", "Terms", "zh")">简体中文</a></li>
<li><a href="@Url.Action("Index", "Terms", "pt-pt")">European Português</a></li>
<li><a href="@Url.Action("Index", "Terms", "pt")">Português</a></li>
这是应该处理点击的操作:
public class TermsController : Controller
{
public ActionResult Index(string id)
{
switch (id)
{
case "de":
return View("de");
case "fr":
return View("fr");
case "it":
return View("it");
case "nl":
return View("nl");
case "hu":
return View("hu");
case "es":
return View("es");
case "zh":
return View("zh");
case "pt":
return View("pt");
case "pt-pt":
return View("pt-pt");
default:
return View();
}
}
这些是我的路线:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Terms",
"{controller}/{id}",
new { controller = "Terms", action = "Index" }
);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
routes.MapRoute(
"ThankYou",
"{controller}/{action}/{email}/{id}"
);
}
从主(即英语)条款页面,第一个(即英语)链接看起来是正确的:
http://localhost:65391/Terms/
为什么其他(即外国)生成的 URL 看起来像这样?
http://localhost:65391/Terms/?Length=2
另外,奇怪的是,如果我手动输入
http://localhost:65391/Terms/de
例如,转到德语的条款页面,那么第一个超链接(即返回到英语条款页面)如下所示:
http://localhost:65391/Terms/de
去这里查看实际站点: