gpt4 book ai didi

c# - 在我的部分观点中语言没有改变?

转载 作者:太空宇宙 更新时间:2023-11-03 16:22:45 25 4
gpt4 key购买 nike

我已经为我的 MVC 3 项目实现了语言支持。

     protected void Application_AcquireRequestState(object sender, EventArgs e)
{
//It's important to check whether session object is ready
if (HttpContext.Current.Session != null)
{
CultureInfo ci = (CultureInfo)this.Session["Culture"];
//Checking first if there is no value in session
//and set default language
//this can happen for first user's request
if (ci == null)
{
//Sets default culture to english invariant
string langName = "en";
//Try to get values from Accept lang HTTP header
if (HttpContext.Current.Request.UserLanguages != null &&
HttpContext.Current.Request.UserLanguages.Length != 0)
{
//Gets accepted list
langName = HttpContext.Current.Request.UserLanguages[0].Substring(0, 2);
}
ci = new CultureInfo(langName);
this.Session["Culture"] = ci;
}
//Finally setting culture for each request
Thread.CurrentThread.CurrentUICulture = ci;
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture(ci.Name);
}
}

然后我通过这个选择我的语言:

        [AllowAnonymous]
public ActionResult ChangeLanguage(string lang, string returnUrl)
{
Session["Culture"] = new CultureInfo(lang);

return Redirect(returnUrl);
}

它会在主视图中加载正确的语言,但不会在部分 View 中加载。我错过了什么吗?

谢谢!

最佳答案

Darin 是对的,代码是正确的。

关于c# - 在我的部分观点中语言没有改变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13394522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com