I am trying to bind date in a model for two cultures (en-US and fr-FR) when the culture is selected en-US. User selects the Item language for creating an entry. For example : Add news in en-US | add news in fr-FR
Model:
[Column(TypeName = "datetime2")]
public DateTime CreatedOn { get; set; }
View:
@Html.TextBox("CreatedOn", Model.CreatedOn, new { @class = "form-control", @id = "datepicker" , @type="text"})
Script for datepicker and parsing:
$(document).ready(function () {
$('#datetimepicker2').datetimepicker({
locale: '@Model.CultureInfoCode',
format: 'L'
}).data("DateTimePicker").date();
//$('#datetimepicker2').moment().format("MM/dd/YYYY");
});
$(document).ready(function () {
$.validator.methods.date = function (value, element) {
moment.locale('@Model.CultureInfoCode'); // CultureInfoCode is the culture of item being entered.
return moment(value);
//parseDate(value, null, "@Model.CultureInfoCode");
// return this.optional(element) || Globalize.parseDate(value) !== null;
}
});
Parsing date seems to work fine also. Model binds all values including date if the culture selected for whole website(en-US ) matches the culture of Item being entered (i.e Add news in English (en-US)). But when I add news in French(fr-FR) and enter date as 26/01/0001, it binds all fields except date and gives value in model as 1/1/0001 and returns in same view displaying error message:
**The value '26/01/0001' is not valid for 'CreatedOn' .**
model.Validate is also false in controller.
Please help. Thanks