Garmaine Staff asked 2 years ago

I'm trying to use a bootstrap datepicker with no luck.

I need to set the endDate to today, and the startDate to 60 day's prior to today.

I also need to have the format value to be yyyy-mm-dd

This is my model:

[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
public DateTime ProductionDate { get; set; }

This is my .cshtml control:

@Html.EditorFor(model => model.ProductionDate, "{0:yyyy-MM-dd}", new { htmlAttributes = new { @class = "form-control datepicker", @type = "date" } })

This is the declaration in my .cshtml file:

$(document).ready(function () {
    $('#ProductionDate').datepicker({
        endDate: '0d',         // cannot select any days past today
        startDate: '-60d',     // cannot select any date before 60 days
        format: 'yyyy-mm-dd',
    });
}

This date picker is not disabling the dates I asked for.

It also does not display the selected date in the text box. After selecting a different date, it shows what I asked for as the default, which is today.

The format attribute setting seems to be working since I'm not getting the dreaded The specified value does not conform to the required format, "yyyy-MM-dd"

Can someone offer some advice as to why the rest of this this is not working?