Skip to content

Localised number format and wrong input type for decimal fields #6566

@ygoe

Description

@ygoe

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:

  1. Using this version of ASP.NET Core 2.1.5
  2. 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]

Metadata

Metadata

Assignees

Labels

Priority:1Work that is critical for the release, but we could probably ship withoutaffected-fewThis issue impacts only small number of customersapi-approvedAPI was approved in API review, it can be implementedarea-mvcIncludes: MVC, Actions and Controllers, Localization, CORS, most templatesbugThis issue describes a behavior which is not expected - a bug.feature-mvc-razor-viewsFeatures related to the Razor view engine for Razor pages and MVC viewsinvestigateseverity-minorThis label is used by an internal tool

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions