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.

Critical bug(?). Problem with Date from Model to View. Not using ISO international format. #4633

@Bartmax

Description

@Bartmax

There's a problem with the input date, the datatype and the view.
Data does't get binded to the view correctly.

Even i'm using en-us culture mvc doesn't use the correct format. I'm pretty sure the ISO international format (yyyy-MM-dd) is accepted for every culture but mvc is not using that.

Startup.cs

var cultureInfo = new CultureInfo("en-US");

app.UseRequestLocalization(
    new RequestLocalizationOptions()
    {
        DefaultRequestCulture = new RequestCulture(cultureInfo),
        SupportedUICultures = new[] { cultureInfo },
        SupportedCultures = new[] { cultureInfo }
    });

view.cshtml:

<form asp-action="Edit" enctype="multipart/form-data">
    <div class="form-horizontal">
        <div asp-validation-summary="ModelOnly" class="text-danger"></div>
        <input type="hidden" asp-for="Id" />
        <div class="form-group">
            <label asp-for="ReleaseDate" class="col-md-2 control-label"></label>
            <div class="col-md-10">
                <input asp-for="ReleaseDate" class="form-control" />
                <span asp-validation-for="ReleaseDate" class="text-danger"></span>
            </div>
        </div>

viewmodel.cs:

        [DataType(DataType.Date)]
        public DateTime? ReleaseDate { get; set; }

generated html:

<input class="form-control" type="date" id="ReleaseDate" name="ReleaseDate" value="6/2/2015" />

rendering:
image

Chrome warning:

The specified value "6/2/2015" does not conform to the required format, "yyyy-MM-dd".

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions