The title might not describe my problem very accurately, but I couldn't find a better way to describe it shortly.
Here's my problem; I'm creating an MVC application, and using the JQuery datepicker to make the pick a date from an input field. Whenever the action loads (/Report/Index), the first time, I need the date to be set to whatever is in the model. It does load the date, but the date format is incorrect: dd-mm-yyyy hh:mm:ss, though I'm changing the dateformat in the initialization function of the datepicker, just as seen here:
$('.datefield').datepicker({ dateformat: 'dd/mm/yy'});
Whenever i change the date within this input field, the format is correct.
How can I make the date from the model, to be the correct date format whenever the action loads?
Markup
<div>
@Html.TextBoxFor(model => model.StartDate, new { @class = "datefield" })
</div>
Model snippet (StartDate)
public class ReportViewModel{
public DateTime StartDate { get; set; }
}
If you need to see more code than this, you're more than welcome to ask
@Html.TextBoxFor(m => m.StartDate, "{0:dd/MM/yyyy}", new { @class = "datefield" })ToString("dd/mm/yyyy"). Using your method gives the following output"23-02-2016". Is there a way for me to change the dash to a forward slash?"{0:dd/MM/yyyy}"does not out put23-02-2016- it outputs23/02/2016- check you code again for errors/typos