I have made a simple mvc app to test globalization/localization. I have made Resources.resx file and Resources.es.resx (spanish) file where I have strings that I want translated.
All strings are translated fine, but with DateTime format I am experiencing difficulties.
In the partial view I am using I use xd-soft datetimepicker for my date field like this:
razor syntax:
<div class="form-group">
@Html.LabelFor(model => model.Date, htmlAttributes: new { @class = "control-label col-md-3" })
<div class="col-md-10">
@Html.EditorFor(model => model.Date, Resources.FormatSave, new { htmlAttributes = new { @class = "form-control input-sm datetimepicker1" } })
@Html.ValidationMessageFor(model => model.Date, "", new { @class = "text-danger" })
</div>
</div>
and the script for datetimepicker looks like this:
<script type="text/javascript">
jQuery('.datetimepicker1').datetimepicker({
format: '@Resources.Format', //when local d.m.Y, when spanish d/m/Y
theme: 'dark',
lang: '@Resources.Language',
closeOnDateSelect: true,
});
</script>
When i use spanish format d/m/Y its alright and when i use d.m.Y i get validation message "The field Date must be a date.".
My model looks like this:
[Display(Name = "Date", ResourceType = typeof(Resources.Resources))]
[Required(ErrorMessageResourceType = typeof(Resources.Resources),
ErrorMessageResourceName = "DateRequired")]
[DataType(DataType.DateTime)]
public DateTime Date { get; set; }