I have a basic aspnet application that works with non-English configuration (Spanish):
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { ...... app.UseRequestLocalization(new RequestLocalizationOptions { DefaultRequestCulture = new RequestCulture(new CultureInfo("es-AR")) ,SupportedCultures = new List<CultureInfo> { new CultureInfo("es-AR") } ,SupportedUICultures = new List<CultureInfo> { new CultureInfo("es") } }); ......... }
In English, a decimal has a decimal part separated by a period, but in Spanish, a comma is used:
- 10256.35 Russian
- 10256.35 Spanish
I have this action in the controller:
[HttpPost] public decimal Test(decimal val) { return val; }
If I use a postman and send json to this action, like this {val: 15.30}, then val in the action returns 0 (binding does not work due to culture). If I send json like this {val: 15,30}, then in action I get 15.30 I have a problem, I need an action to accept decimal places with commas, because this is a format that comes from entering text type in application forms . But I also need to accept a decimal with a dot that comes from a request in json format. It is not possible to specify decimal / float in json that takes a comma (sending it as a string is not an option). How can i do this??? I make myself crazy with that.
Thanks!!
json c # asp.net-mvc asp.net-core localization
snekkke
source share