I'm using JQueryUI Datepicker in my ASP.NET MVC 5 project. I want user to enter dates in mm/dd/yy format in Create and Edit views. This is what I accomplished so far :
This is my model :
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString =
"{0:MM-dd-yyyy}",
ApplyFormatInEditMode = true)]
public DateTime ProjectDeadline { get; set; }
This is jQuery code in _Layout.cshtml :
<script type="text/javascript">
$(function () {
$('.date-picker').datepicker({ dateFormat: "MM-dd-yy" });
})
</script>
If I don't touch Date in Edit and hit Save, I get a warning saying :
The field ProjectDeadline must be a date.
I tried many possibilities to have what I want, but that's the best I can get. I got errors in my most of attempts. Can you tell me how I can fix my code to get mm/dd/yyyy format in Date fields properly? Thanks.