C# ASP.NET MVC选定语言
我正在制作简单的多语言网站。让我在母版页上选择语言,使用C# ASP.NET MVC选定语言,c#,asp.net-mvc-4,cookies,C#,Asp.net Mvc 4,Cookies,我正在制作简单的多语言网站。让我在母版页上选择语言,使用HttpCookie cookies=HttpContext.Request.cookies[“语言”]正常吗以了解当前选择的语言?还是存在另一种更好的方法 家庭控制器: public class HomeController : Controller { // // GET: /Home/ public ActionResult Index() { HttpCookie cookies =
HttpCookie cookies=HttpContext.Request.cookies[“语言”]正常吗在HomeController中选择code>以了解当前选择的语言?还是存在另一种更好的方法
家庭控制器:
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
HttpCookie cookies = HttpContext.Request.Cookies["Language"];
return View();
}
}
public class LanguageController : Controller
{
//
// GET: /Language/
public ActionResult Index()
{
return View();
}
public ActionResult Change(string abbr)
{
if (abbr!=null)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(abbr);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(abbr);
}
HttpCookie cookies = new HttpCookie("Language");
cookies.Value = abbr;
Response.Cookies.Add(cookies);
return RedirectToAction("Index","Home");
}
}
语言控制器:
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
HttpCookie cookies = HttpContext.Request.Cookies["Language"];
return View();
}
}
public class LanguageController : Controller
{
//
// GET: /Language/
public ActionResult Index()
{
return View();
}
public ActionResult Change(string abbr)
{
if (abbr!=null)
{
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(abbr);
Thread.CurrentThread.CurrentUICulture = new CultureInfo(abbr);
}
HttpCookie cookies = new HttpCookie("Language");
cookies.Value = abbr;
Response.Cookies.Add(cookies);
return RedirectToAction("Index","Home");
}
}
_布局:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<title>@ViewBag.Title</title>
@Styles.Render("~/Content/css")
@Scripts.Render("~/bundles/modernizr")
</head>
<body>
@Html.ActionLink(MultiLanguages.Resources.HomeText.About, "Home")
@Html.ActionLink("France", "Change", "Language", new { abbr = "fr" }, null)
@Html.ActionLink("English", "Change", "Language", new { abbr = "en" }, null)
@RenderBody()
@Scripts.Render("~/bundles/jquery")
@RenderSection("scripts", required: false)
</body>
</html>