这是我的模型类的一个片段
[Required]
[DataType(DataType.Date)]
[Display(Name = "Birth Day")]
public DateTime customerBirthDate { get; set; } = DateTime.Today;
这是我的剃须刀文件的一个片段
<div class="wrap-input100 validate-input">
<span class="label-input100">Date of Birth</span>
<InputDate class="input100" id="birthday" name="birthday" @bind-Value="CurrentCustomerSubmission.customerBirthDate" />
<ValidationMessage For="@(() => Model.customerBirthDate)" />
</div>
当我从InputDate字段中删除日期时,我希望它显示
"出生日期"字段必须是日期">
但我实际看到的是
"customerBirthDate字段必须是一个日期">
我在Chrome 中进行了测试
你可以这样做
[Required]
[DataType(DataType.Date,ErrorMessage = "The Birth Day field must be a date.")]
[Display(Name = "Birth Day")]
public DateTime customerBirthDate { get; set; } = DateTime.Today;
[Required(ErrorMessage ="{0} field is Required"]
[DataType(DataType.Date,ErrorMessage = "{0} field must be a date.")]
[Display(Name = "Birth Day")]
public DateTime customerBirthDate { get; set; } = DateTime.Today;
您可以使用所需属性的错误消息