1

i have this Model:

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

and it works fine but when i go into edit mode it looks like this, which makes it NULL if i try to save it.

Bday EditView

i prefer to keep the Datepicker i want it to get into the format of dd-mm-yyyy. and preferable solved through my viewModel.

View:

 <div class="form-group">
        @Html.LabelFor(model => model.bday, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.bday, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.bday, "", new { @class = "text-danger" })
        </div>
    </div>
  • Show your view code! (and assuming your using `@Html.EditorFor()` then it needs to be `DataFormatString = "{0:yyyy-MM-dd}"` (ISO format). But it generates a HTML-5 datepicker and its only supported in Chrome and Edge. –  Mar 29 '17 at 10:53
  • @StephenMuecke Added the Viewcode, Sorry forgot about it. – Jakko legel Mar 29 '17 at 11:00

0 Answers0