I am trying to use model validation in MVC.Net Core and cannot replace this default error message "Value" is not valid.
In theory, we can replace our own error message using ErrorMessage
Annotation in the model. But I could not find a way to make this work.
My model
[Required(ErrorMessage = "Date Required")]
[DataType(DataType.Date, ErrorMessage = "Invalid Date Format")]
[Display(Name = "Appointment Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime AppointmentDate { get; set; }
I put different ErrorMessage
for tags Required
and DataType
as shown above.
My html view
<div class="col-md-2">
<input class="form-control" asp-for="AppointmentDate">
<span asp-validation-for="AppointmentDate" class="text-danger"></span>
</div>
Could you help me, how can I replace this error message? Thanks.
source
share