ASP.NET Core 货币格式无法正常工作

Bil*_*ill 4 .net c# asp.net asp.net-mvc asp.net-core

在尝试[DataType(DataType.Currency)]使用属性显示货币并使用 时@Html.DisplayFor(model => model.Variable),在本地调试时,格式无法在我的 OS X 计算机上正确显示。它显示为一个¤符号而不是$

Aar*_*rts 7

您可以以编程方式为您的服务器设置文化信息 Startup.cs

public Startup(IHostingEnvironment env)
{
    CultureInfo.DefaultThreadCurrentCulture = new CultureInfo("en-US");

    var builder = new ConfigurationBuilder()
        .SetBasePath(env.ContentRootPath)
        .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
        .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
        .AddEnvironmentVariables();
    Configuration = builder.Build();
}
Run Code Online (Sandbox Code Playgroud)