MVC 3 DatePicker 验证消息
我有一个日期选择器,我想在输入非日期内容时更改错误消息。
这是我的模型:(我尝试将 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为文本框不会输出用于验证的完整元数据。
尝试使用文本框代替。
问候
西
I dont think textbox outputs the full metadata for validation.
Try using textboxfor instead.
Regards
Si