我有这个在每个“使用条款”页面的几个译本的顶部:
<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
去这里看看实际的网站:
http://inrix.com/traffic/terms