简体   繁体   中英

Decimal separator is changing back to a dot after navigating to another page

For my web application I want the prices to have a comma as decimal separator on all my pages of my web application. I managed this by adding these line of codes in the program.cs:

CultureInfo.CurrentCulture = new CultureInfo("nl-NL");
CultureInfo.CurrentUICulture = new CultureInfo("nl-NL");

And when I run my web application, I see the comma as decimal separator. But, when I navigate to a different page, also having prices, the decimal separator has changed into a dot. And when I navigate back to the page where the comma was shown as decimal separator, it now shows a dot as decimal separator as well.

It looks like the comma as decimal separator only works the first time. After that, it goes back to the dot. I cannot figure out why this is happening or how to fix this. Can someone perhaps explain to me what the cause of my issue could be?

A quick and dirty approach is to also set DefaultThreadCurrentCulture and DefaultThreadCurrentUICulture in program.cs .

var cultureInfo = new CultureInfo("nl-NL");
CultureInfo.CurrentCulture = cultureInfo;
CultureInfo.CurrentUICulture = cultureInfo;
CultureInfo.DefaultThreadCurrentCulture = cultureInfo;
CultureInfo.DefaultThreadCurrentUICulture = cultureInfo;

Official documentation on localization in Blazor: https://learn.microsoft.com/en-us/as.net/core/blazor/globalization-localization

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM