即使在.net core 2.1中将文化设置为英式,也将模型绑定中的日期设置为美式格式

时间:2018-07-26 15:19:29

标签: .net asp.net-mvc model asp.net-core-mvc model-binding

.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>

enter image description here

Sample Project is on GitHub

1 个答案:

答案 0 :(得分:-1)

在GitHub CaseRaisedInGitHub中提出了此问题,并创建了一个演示项目来解释该问题,网址为 https://github.com/nabinkjha/DateTimeLocalization/tree/master/GetSearchDemo

DemoProjectLink