-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Describe the bug
With a model that contains a decimal
property, this doesn't work with a locale that uses a decimal comma:
<input asp-for="Number">
<input asp-for="Number" type="number">
To Reproduce
Steps to reproduce the behavior:
- Using this version of ASP.NET Core 2.1.5
- Create the model class and the HTML razor view, then run it
Code:
class Model
{
public decimal Number { get; set; } = 1.0m;
}
Expected behavior
This should be the rendered HTML:
<input type="number" name="Number" value="1.0">
This happens instead, for the two view variants from the top:
<input type="text" name="Number" value="1,0">
<input type="number" name="Number" value="1,0">
The first issue is that the decimal
type isn't rendered with the type="number"
attribute. If I fix this myself by adding the attribute, the field remains completely empty because there is a comma instead of a point in the value. This shouldn't be localised because then no browser or frontend library can handle the value anymore.
PS: I haven't even got to try what happens when the correct value "1.0" is sent back to the controller and the model binder should convert it to a decimal
type. It probably fails for the same reason.
[User reference: Configuration/Endpoint/Edit/Factor]