Problems with default behavior of culture of ModelBinder

43 Views Asked by At

I'm developing from Brazil. Here, the default number format is, by example, "1.000,00" (dots instead of commas, and vice-versa).

My problem is with the default settings for MVC Core 2. Just create a default ASP.Net MVC Core Web App, create a model like this:

public class TestModel
{
    public decimal Salary { get; set; } = 1.5M
}

Create the default scaffoldings for this models, and you will see this page:enter image description here

Asp.Net MVC correctly detects my culture, and display the value with commas instead of dots. The funny part is when I try submit this:

enter image description here

Ok, the page displays correctly, but the validation ui dont get my culture correctly... I think this bizzarre, show data in some culture and expect receive back in other culture is... inconsistent. But, ok, for sake of tests, I change "1,50" to "1.50". I submit and I receive this on the server side:

enter image description here

I have LOTS of solutions for this problem, but I think really odd this behaviour. If the user is expected receive data in one format, by default, I think must be displayed in the same format.

But ok, what the correct (expected?) way to manage this situation?

0

There are 0 best solutions below