更改默认的ASP.NET MVC5验证消息

时间:2019-11-19 22:37:05

标签: c# jquery asp.net asp.net-mvc twitter-bootstrap

这是我模型的日期属性:

[DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:yyyy.mm.dd}")]
[Required(ErrorMessage = "You need to fill this")]
[DataType(DataType.DateTime, ErrorMessage = "Type proper date")]
[Display(Name = "Weight Date")]
public DateTime? WeightDate { get; set; }

这就是我渲染引导程序的datepicker

的方式
@Html.EditorFor(x => x.WeightDate, new { htmlAttributes = new { @id="WeightDate" @class = "form-control datepicker", @required = "required" }})
@Html.ValidationMessageFor(m => m.WeightDate, "", new { @class = "text-danger" })

验证似乎有效(输入空datepicker值时,我可以看到“您需要填写此信息”)。问题是我可以看到其他我不想看到的消息(或至少更改了他们的消息):

输入无效数据时,(从客户端)出现错误:

The field Weight date must be a date.

提交无效数据时,出现错误(从服务器端):

The value '202441.02.03' is not valid for Weight date.

如何更改这些消息?

0 个答案:

没有答案