I am trying to load today's date into the HTML5 date input type in Core 1.1, however when I set today's date in the controller, I get the following error in the console on the page.
The specified value "9/3/2017 12:00:00 AM" does not conform to the required format, "yyyy-MM-dd".
AddWorkOrder.cshtml
<div class="form-group">
<b>Issue Date:</b>
@Html.TextBoxFor(Model => Model.NewWorkOrder.workOrderIssueDate, new { @class = "form-control", @type = "date", @value = Model.NewWorkOrder.workOrderIssueDate.ToString("yyyy-MM-dd") })
@Html.ValidationMessageFor(Model => Model.NewWorkOrder.workOrderIssueDate, "", new { @class = "valColor" })
</div>
WorkOrderController.cs
// GET : /WorkOrder/AddWorkOrder
public IActionResult AddWorkOrder()
{
WorkOrderViewModel workOrderVm = new WorkOrderViewModel();
using (var db = new WorkOrderDBContext())
{
workOrderVm.NewWorkOrder = new WorkOrder();
workOrderVm.NewWorkOrder.workOrderIssueDate = DateTime.Today;
}
return View(workOrderVm);
}
I have tried setting the value of the textbook to be @value = DateTime.Today.ToString("yyyy-MM-dd") and that does not load the date either.
workOrderIssueDateproperty asstringand convert theDateTime.Todayto string like the followingworkOrderVm.NewWorkOrder.workOrderIssueDate = DateTime.Today.ToString("yyyy-MM-dd");?