Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Decimal binding problem on non English Culture #5331

@airomero

Description

@airomero

Hi everyone. I have an aspnet core app that runs with a non english configuration (spanish):

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory 
{
    ......
    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 number has its decimal part delimited with a dot, but in spanish a comma is used:

  • 10256.35 english
  • 10256,35 spanish

I have this action in a controller:

 [HttpPost]
 public decimal Test(decimal val)
 {
     return val;
 }

If I use postman and send to that action a json like this {val: 15.30}, then val in the action recives a 0 (binding not working because of the culture). If I send a json like this {val: 15,30} then in the action I recive 15.30
The problem I have is, I need the action to accept decimals with commas, because that is the format that comes from inputs type text in the app's forms. But i also need to accept decimal with a dot that comes from request in json format. There is no way to specify a decimal/float in json that accepts a comma (send it as string is not an option). How can I do this??? I'm driving my self crazy with this.

Thanks!!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions