Reputation: 99
So I have researched this for several days and I am trying to put an initial value to a date. It needs to be 4 weeks from yesterday so the model has this in it:
[DataType(DataType.Date, ErrorMessage = "Date Only")]
[DisplayFormat(DataFormatString = "{0:dd-MMM-yyyy}", ApplyFormatInEditMode = true)]
[Display(Name = "Starting Date")]
public DateTime StartDate { get; set; } = DateTime.Today.AddDays(-29);
This is the code for the view:
@Html.EditorFor(model => model.StartDate, new { htmlattributes = new { @class = "datepicker" } })
Yet, whether I have the default date in the model or not, the view yields this:
I want it to be changeable but this is the initial value I am trying to deploy.
I have also tried this in the view. No Change.
@Html.EditorFor(model => model.StartDate, new { htmlattributes = new { @class = "datepicker", @Value = DateTime.Today.AddDays(-29) } })
Upvotes: 0
Views: 573
Reputation: 1
@Html.TextBoxFor(model => model.BirthDate, "{0:yyyy-MM-dd}", new { @class = "form-control", type = "date" })
Upvotes: 0