As Stephen Mukke said, you need to set the property value on the model.
// in controller method that returns the view. MyModel model = new MyModel(); model.Date = DateTime.Today; return View(model);
And your razor will:
@Html.TextBoxFor(x => x.Date, "{0:yyyy-MM-dd}", new { @class = "form-control", @type = "date"})
Note that the id and name properties should be automatically assigned the name of the property when using the For method, for example @Html.TextBoxFor() , so you do not need to explicitly set the id attribute.
ps2goat
source share