MVC 3 DatePicker 验证消息

发布于 2024-12-29 20:20:30 字数 791 浏览 2 评论 0原文

我有一个日期选择器,我想在输入非日期内容时更改错误消息。

这是我的模型:(我尝试将 DataType.Date 更改为 DataType.DateTime,仍然不起作用)

    [Display(Name = "Date :")]
    [DataType(DataType.Date,ErrorMessage="Date non valide.")]
    public DateTime? Evaluation_AVQ { get; set; }

这是我的视图:

<script type="text/javascript">
$(document).ready(function () {
    $('.date').datepicker();
});
</script>

@Html.LabelFor(model => model.Evaluation_AVQ) 
 <br />
@Html.TextBox("Evaluation_AVQ", Model.Evaluation_AVQ == null ? "" : Model.Evaluation_AVQ.Value.ToLongDateString(), new { @class = "date" })
@Html.ValidationMessageFor(model => model.Evaluation_AVQ)

因此,如果我在文本框中输入“fwefwe”,它将显示消息:值“fwefwe”不适用于日期:。

如何将此消息更改为“日期无效”?

谢谢你的帮助

I have a datepicker and I want to change the error message when I enter something that is not a date.

Here is my model : (I've tried to change DataType.Date to DataType.DateTime, still not working)

    [Display(Name = "Date :")]
    [DataType(DataType.Date,ErrorMessage="Date non valide.")]
    public DateTime? Evaluation_AVQ { get; set; }

Here is my view :

<script type="text/javascript">
$(document).ready(function () {
    $('.date').datepicker();
});
</script>

@Html.LabelFor(model => model.Evaluation_AVQ) 
 <br />
@Html.TextBox("Evaluation_AVQ", Model.Evaluation_AVQ == null ? "" : Model.Evaluation_AVQ.Value.ToLongDateString(), new { @class = "date" })
@Html.ValidationMessageFor(model => model.Evaluation_AVQ)

So if I enter 'fwefwe' in the textbox it will show the message : The value 'fwefwe' is not valid for Date :.

How can I change this message to "Date non valide" ?

Thank you for the help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

请持续率性 2025-01-05 20:20:30

我认为文本框不会输出用于验证的完整元数据。

尝试使用文本框代替。

@Html.TextBoxFor(m => m.Evaluation_AVQ, new { @class = "date", Value = Model.Evaluation_AVQ == null ? "" : Model.Evaluation_AVQ.Value.ToLongDateString() })

问候

西

I dont think textbox outputs the full metadata for validation.

Try using textboxfor instead.

@Html.TextBoxFor(m => m.Evaluation_AVQ, new { @class = "date", Value = Model.Evaluation_AVQ == null ? "" : Model.Evaluation_AVQ.Value.ToLongDateString() })

Regards

Si

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文