Saturday, February 16, 2019

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd.MM.yyyy}")] displays date as intended, but on save it's converted wrong.

As the topic says:

 [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd.MM.yyyy}")] public DateTime? KeyStartDate { get; set; } 

That works great displaying it:

<div class="form-group"> <label asp-for="KeyStartDate">@Resources.Global.StartDate</label> <input data-toggle="datepicker" asp-for="KeyStartDate" class="form-control" /> <span asp-validation-for="KeyStartDate" class="text-danger"></span> </div> 

but when I submit the form the date is parsed wrong e.g. "MM/dd/YYYY". So if I choose the date 01.02.2019 (February 1st) the thing interprets it as 01/02/2019 (January 2nd).

What to do?

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd.MM.yyyy}")] displays date as intended, but on save it's converted wrong. Click here
  • Blogger Comment
  • Facebook Comment

0 comments:

Post a Comment

The webdev Team