After hours of searching, I just solved this problem with a few lines of code
Your model
[Required(ErrorMessage = "Enter the issued date.")] [DataType(DataType.Date)] public DateTime IssueDate { get; set; }
Razor page
@Html.TextBoxFor(model => model.IssueDate) @Html.ValidationMessageFor(model => model.IssueDate)
JQuery DatePicker
<script type="text/javascript"> $(document).ready(function () { $('#IssueDate').datepicker({ dateFormat: "dd/mm/yy", showStatus: true, showWeeks: true, currentText: 'Now', autoSize: true, gotoCurrent: true, showAnim: 'blind', highlightWeek: true }); }); </script>
Webconfig file
<system.web> <globalization uiCulture="en" culture="en-GB"/> </system.web>
Your text box will now take the format "dd / MM / yyyy .
iYogi Sep 01 '13 at 12:54 on 2013-09-01 12:54
source share