So I'm trying to use a datepicker from http://www.eyecon.ro/bootstrap-datepicker/
I'm having the problem to set a default value for this datepicker. It shows me the format "0001-01-01 00:00:00" before I can set a date. What I want to do is to show todays date! I create the DOM as follows, which isn't a problem..
<div>
@Html.EditorFor(model => model.ValidationValidFrom, new { htmlAttributes = new { @class = "form-control", @id = "ValidationValidFrom" }})
</div>
This creates the input with the id "ValidationValidFrom". And my jQuery code for the datepicker is as follows:
$("#ValidationValidFrom").datepicker({
format: 'yyyy-mm-dd',
defaultDate: new Date()
});
The only thing that works is the attribute format, the defaultDate doesn't work for some reason, I have tried other attributes shown in other threads, but to no avail..
The generated code looks like this:
<input class="form-control text-box single-line" data-val="true" data-val-date="The field ValidationValidFrom must be a date." data-val-required="The ValidationValidFrom field is required." id="ValidationValidFrom" name="ValidationValidFrom" type="datetime" value="0001-01-01 00:00:00">
model.ValidationValidFrom(and please confirm the data type and datatype anotation) in your model in the controller?EditorFor, you don't need to specify ID and it will likely break your binding.