I've saw about 1k posts on this, but I must have missed something.
Basically, I am trying to use dd/MM/yyyy format in my site, problem occurs at validation.
I've a ViewModel:
public class LoanBaseViewModel
{
public int LoanId { get; set; }
[Required]
[DataCompareValidation("ReturnDate", ErrorMessage = "Return date should be later than loan date")]
[DataType(DataType.Date)]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime LoanDate { get; set; }
[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:MM/dd/yyyy}")]
[DataType(DataType.Date)]
public DateTime? ReturnDate { get; set; }
}
In my EditorTemplate I've This:
@model System.Nullable<System.DateTime>
@if (Model.HasValue)
{
@Html.TextBox("", String.Format("{0:dd/MM/yyyy}", Model.Value), new { @class = "jq-date" })
}
else
{
@Html.TextBox("", "", new { @class = "jq-date" })
}
On page Load I attach a Jquery DatePicker on the jq-date.
$("#loanForm").find(".jq-date").datepicker({ dateFormat: 'dd/mm/yy' });
Display works fine, but every time i tried to save, it tells me date is not in correct format if I use a dd/MM/yyyy date.
Any idea why?
I've been trying for like one hour and it's driving me insane!
Thanks for your time
Tom
Edit: didn't work better What is really weird is that it does work on my laptop, but not in my desktop both of them are display date in dd/MM/yyyy, my laptop accepts 25/08/2013 but not my desktop...
Edit: Solution is here: stackoverflow.com/a/13528769/1741443.