Tôi có điều này ở phía trên cùng của mỗi vài bản dịch của "Quy định sử dụng" trang:@ Url.Action nhận Chiều dài = 2 nối
<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>
Đây là hành động mà nên xử lý các nhấp chuột:
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();
}
}
và đây là những tuyến đường của tôi:
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}"
);
}
Từ chính (ví dụ, tiếng Anh) trang Điều khoản này, người đầu tiên (ví dụ, tiếng Anh) liên kết trông cor rect:
http://localhost:65391/Terms/
Tại sao URL khác được tạo ra (ví dụ: nước ngoài) trông như thế này?
http://localhost:65391/Terms/?Length=2
Ngoài ra, kỳ quặc, nếu tôi tự gõ vào
http://localhost:65391/Terms/de
ví dụ, và đi đến trang Điều khoản bằng tiếng Đức, sau đó các siêu liên kết đầu tiên (tức là trở lại trang Điều khoản tiếng Anh) vẻ như thế này:
http://localhost:65391/Terms/de
tới đây để xem các trang web thực tế:
http://inrix.com/traffic/terms
Chỉ sử dụng một thẻ làm cho câu hỏi của bạn khó có thể khám phá. Bạn nên gắn thẻ ít nhất với thẻ vesion MVC. như asp.net-mvc-3 hoặc asp.net-mvc-4, v.v. – nemesv