我创建了一个asp.net核心mvc项目。
startup.cs
var supportedCultures = new[]
{
new CultureInfo("en-GB"),
new CultureInfo("de-DE"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
SupportedCultures = supportedCultures, // Formatting numbers, dates, etc.
SupportedUICultures = supportedCultures // UI strings that we have localized.
});
MyActionFilter.cs
public override async Task OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
{
Thread.CurrentThread.CurrentCulture = Thread.CurrentThread.CurrentUICulture = new CultureInfo(user.CountryCode);
}
CountryCode
的值为"en-GB"
或"de-DE"
我在剃刀文件中使用@ Resource.MyKey。
在我的ManageController.Index操作中,我返回一个视图,我将国家代码“de-DE”更新为“en-GB”,将新值保存到数据库...
[HttpPost]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Edit(RegionViewModel regionViewModel)
{
var user = HttpContext.GetUser();
user.TimeZone = regionViewModel.SelectedTimeZone;
user.CountryCode = regionViewModel.SelectedCountryCode;
await _userManager.UpdateAsync(user);
return RedirectToAction(nameof(Index));
}
...并返回我的项目控制器索引视图,但UI仍显示德语本地化文本。
为什么?我忘记配置了吗?