这是我模型的日期属性:
[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.
如何更改这些消息?