.net core 2.1中用于日期的模型绑定是将日期值设置为美国格式,即使将区域性信息设置为英国格式。
有什么想法吗?
这是我的启动文件代码段
var enGbCulture = new CultureInfo("en-GB");
CultureInfo.DefaultThreadCurrentCulture = enGbCulture;
CultureInfo.DefaultThreadCurrentUICulture = enGbCulture;
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture(enGbCulture),
SupportedCultures = new List<CultureInfo> { enGbCulture },
SupportedUICultures = new List < CultureInfo > { enGbCulture },
RequestCultureProviders = new List<IRequestCultureProvider>
{
new QueryStringRequestCultureProvider { },
new CookieRequestCultureProvider { },
},
});
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
});
及以下在视图中打印正确的文化信息
<div>Current Culture: @CultureInfo.CurrentCulture.DisplayName</div>
<div>Current UI Culture: @CultureInfo.CurrentUICulture.DisplayName</div>
<div>Current Thread Culture: @Thread.CurrentThread.CurrentCulture.DisplayName;</div>
答案 0 :(得分:-1)
在GitHub CaseRaisedInGitHub中提出了此问题,并创建了一个演示项目来解释该问题,网址为 https://github.com/nabinkjha/DateTimeLocalization/tree/master/GetSearchDemo