jor*_*ton 5 asp.net asp.net-mvc asp.net-web-api asp.net-core
我在 asp net core mvc 中的十进制数字方面遇到了一些问题。我通过将其添加到 web.config 来使其在常规 ASP Net 应用程序中工作:
<system.web>
...
<globalization uiCulture="en" culture="en-US"/>
</system.web>
Run Code Online (Sandbox Code Playgroud)
但是,由于核心应用程序中没有 web.config,我不太确定该怎么做。核心中最接近的近似值会是什么样子?
在 Asp.Net Core 中,本地化是在 Startup.ConfigureServices 方法中配置的,并且可以在整个应用程序中使用:
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddMvc()
.AddViewLocalization(LanguageViewLocationExpanderFormat.Suffix)
.AddDataAnnotationsLocalization();
Run Code Online (Sandbox Code Playgroud)
请求的当前文化是在本地化中间件中设置的。该方法中启用了本地化中间件Startup.Configure。必须在任何可能检查请求区域性的中间件之前配置本地化中间件(例如,app.UseMvcWithDefaultRoute())。
var supportedCultures = new[]
{
new CultureInfo("en-US"),
new CultureInfo("fr"),
};
app.UseRequestLocalization(new RequestLocalizationOptions
{
DefaultRequestCulture = new RequestCulture("en-US"),
// Formatting numbers, dates, etc.
SupportedCultures = supportedCultures,
// UI strings that we have localized.
SupportedUICultures = supportedCultures
});
app.UseStaticFiles();
// To configure external authentication,
// see: http://go.microsoft.com/fwlink/?LinkID=532715
app.UseAuthentication();
app.UseMvcWithDefaultRoute();
Run Code Online (Sandbox Code Playgroud)
更多详细信息,您可以参考官方文档。
| 归档时间: |
|
| 查看次数: |
9782 次 |
| 最近记录: |