我在使用 mvc5 构建的 Web 应用程序中使用资源文件切换语言
在索引文件中它读取我设置的文化值。
我从 layout.cshtml 调用 set culture 方法并使用以下代码调用它的值。
@{
Layout = "~/Views/Shared/_Layout.cshtml";
if (!Request["dropdown"].IsEmpty())
{
Culture = UICulture = Request["dropdown"];
}
在索引页面中,语言加载正确,但是当我从那里转到下一页时,它加载默认语言德语,但资源仅从英语资源文件中读取。
请帮我解决这个问题..任何人
最佳答案
对于全局设置,我建议您将以下行添加到 global.asax.cs 文件中:(在此示例中,文化设置为 Israel hebrew)
protected void Application_Start()
{
//The culture value determines the results of culture-dependent functions, such as the date, number, and currency (NIS symbol)
System.Globalization.CultureInfo.DefaultThreadCurrentCulture = new System.Globalization.CultureInfo("he-il");
//System.Globalization.CultureInfo.DefaultThreadCurrentUICulture = new System.Globalization.CultureInfo("he-il");
}
关于c# - 如何在 mvc5 中将文化设置为全局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24060184/