MVC EditorFor Date does not show value

I want to show the date in German date format (dd.MM.yyyy) from a model in an MVC application and provide the user with a datepicker. I asked a lot of questions that have already been answered on this topic, but still I can not get them to work. I tried this on Firefox and Edge, with the same results for every step.

Step 1:

Model:

private DateTime? inbetriebnahmedatum;

public DateTime? Inbetriebnahmedatum
{               
    get { return inbetriebnahmedatum; }
    set { inbetriebnahmedatum = value; OnPropertyChanged(new PropertyChangedEventArgs("Inbetriebnahmedatum")); }
}

View:

@Html.EditorFor(model => model.Inbetriebnahmedatum, new { htmlAttributes = new { @class = "form-control", placeholder = "Datum eingeben" } })

Result: No Datepicker, time is displayed, validation error enter image description here

Step 2: Added DataType

Model:

private DateTime? inbetriebnahmedatum;

[DataType(DataType.Date)]
public DateTime? Inbetriebnahmedatum
{
    get { return inbetriebnahmedatum; }
    set { inbetriebnahmedatum = value; OnPropertyChanged(new PropertyChangedEventArgs("Inbetriebnahmedatum")); }
}

View: no change

Result: value not loaded. enter image description here

Step 3: added DisplayFormat, removed Datatype

Model:

private DateTime? inbetriebnahmedatum;

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd.MM.yyyy}")]
public DateTime? Inbetriebnahmedatum
{
    get { return inbetriebnahmedatum; }
    set { inbetriebnahmedatum = value; OnPropertyChanged(new PropertyChangedEventArgs("Inbetriebnahmedatum")); }
}

View: no change

Result: date is displayed, but no datepicker and validation error enter image description here

Step 4: Added ui Culture in Web.config

Web.config

<globalization uiCulture="de-DE" culture="de-DE" />

Result: The same enter image description here

Step 5: added data type again

Model:

private DateTime? inbetriebnahmedatum;

[DataType(DataType.Date)]
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd.MM.yyyy}")]
public DateTime? Inbetriebnahmedatum
{
    get { return inbetriebnahmedatum; }
    set { inbetriebnahmedatum = value; OnPropertyChanged(new PropertyChangedEventArgs("Inbetriebnahmedatum")); }
}

Result: value not loaded, datepicker shows enter image description here

0
1

, . → : 01/01/2018

[DisplayFormat(DataFormatString = "{0:MMM dd, yyyy}")]

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:dd/MM/yyyy}")]

0

All Articles