Reputation: 9013
I want to show date in format "dd/MM/yyyy" with bootstrap datepicker. I have the following code:
@Html.TextBoxFor(model => model.StartDate, "{0:dd/MM/yyyy}", new { @class = "w8em format-y-m-d form-control", @value=Model.StartDate.ToShortDateString("dd/MM/yyyy") })
It shows i.e. '20/10/2015' (20 oct 2015). But when I click on it to open datapicker it selects 10 august 2015 (why august? I don't know). If I just close datepicker (no selects anything inside) - textbox value is changed to '08/10/2015'. If I don't touch anything on page and just click "save" on form, StartDate validator says "Start date incorrect" and opens datepicker automatically. Why so strange behavior and how to change format to dd/MM/yyyy forcibly? Browser is Chrome, the latest ukrainian version, datepicker is shown on english...
UPDATED:
I have added
$('#@Html.IdFor(p=>p.StartDate)').datepicker({ dateFormat: 'dd/mm/yyyy' });
and does not work
Upvotes: 0
Views: 88
Reputation: 9013
should be
$('#@Html.IdFor(p=>p.StartDate)').datepicker({ format: 'dd/mm/yyyy' });
instead of
$('#@Html.IdFor(p=>p.StartDate)').datepicker({ dateFormat: 'dd/mm/yyyy' });
(look at datepicker parameters, should be 'dateFormat' instead of 'format')
Upvotes: 1