[英]translate route url name in MVC 5
您可以將帶有某種“語言”的路由注冊為路徑的第一部分,並處理諸如行動參數之類的信息。
routes.MapRoute(
name: "Category",
url: "{language}/Category",
defaults: new { controller = "Category", action = "Index" },
);
ActionResult Index(string language,...)
{
// set language based on Url
// i.e. if you are using "en-GB" as language (.Net culture names)
Thread.CurrentThread.CurrentCulture = new CultureInfo(language);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(language);
}
請注意,有很多方法可以重構此類代碼以避免重復(例如,編寫ActionFilter即可)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.