mvc html5 input,html - MVC 4 Razor adding input type date - Stack Overflow

The input date value format needs the date specified as per http://tools.ietf.org/html/rfc3339#section-5.6 full-date.

So I've ended up doing:

I did try doing it "properly" using:

[DataType(DataType.Date)]

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

public DateTime LastStartDate

{

get { return lastStartDate; }

set { lastStartDate = value; }

}

with

@Html.TextBoxFor(model => model.LastStartDate,

new { type = "date" })

Unfortunately that always seemed to set the value attribute of the input to a standard date time so I've ended up applying the formatting directly as above.

Edit:

According to Jorn if you use

@Html.EditorFor(model => model.LastStartDate)

instead of TextBoxFor it all works fine.