Skip to content

MVC localization binding/validation not working with decimals and dates #22937

Open
@ejohnson-dotnet

Description

@ejohnson-dotnet

Is there an existing issue for this?

  • I have searched the existing issues

Description

I am using Abp with MVC. If I have a page that binds an input to a model decimal/double or a DateTime and I change the language to Spanish or Italian, the data binding will fail when posting the form data. The DateTime will be a null value. The double will not parse the decimal separator correctly so "2.34" returns "234". If I try entering "2,34" the validation fails saying "El campo Amount debe ser un numero" i.e. the value must be a number.

Reproduction Steps

Create a new Razor page with the model having this code:

    [BindProperty]
    [DataType(DataType.Date)]
    public DateTime? StartDate { get; set; }
    [BindProperty]
    public double? Amount { get; set; }

public async Task<IActionResult> OnPostAsync()
{

    if (StartDate == null)
        throw new ArgumentNullException(nameof(StartDate), "StartDate cannot be null.");

    return NoContent();
}

In the razor view, add this:

<form method="post">
    <abp-input asp-for="StartDate" />
    <abp-input asp-for="Amount" />

    <abp-button type="submit" text="Submit" button-type="Primary" />
</form>

When inspecting the posted data in the OnPostAsync, the Amount will not be correct.

Expected behavior

The Amount should be submitted as a decimal value, and the DateTime should not be null.

Actual behavior

No response

Regression?

No response

Known Workarounds

No response

Version

9.1.3

User Interface

MVC

Database Provider

EF Core (Default)

Tiered or separate authentication server

None (Default)

Operation System

Windows (Default)

Other information

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions