【发布时间】:2015-07-08 08:58:25
【问题描述】:
我制作了一个简单的 mvc 应用程序来测试全球化/本地化。 我制作了 Resources.resx 文件和 Resources.es.resx(西班牙语)文件,其中有我想要翻译的字符串。
所有字符串都翻译得很好,但使用 DateTime 格式 我遇到了困难。
在我使用的部分视图中,我将 xd-soft datetimepicker 用于我的日期字段,如下所示:
剃刀语法:
<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>
datetimepicker 的脚本如下所示:
<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>
当我使用西班牙格式 d/m/Y 时没问题,当我使用 d.m.Y 时,我收到验证消息“字段日期必须是日期。”。
我的模型如下所示:
[Display(Name = "Date", ResourceType = typeof(Resources.Resources))]
[Required(ErrorMessageResourceType = typeof(Resources.Resources),
ErrorMessageResourceName = "DateRequired")]
[DataType(DataType.DateTime)]
public DateTime Date { get; set; }
【问题讨论】:
标签: jquery asp.net-mvc localization date-format globalization