I'm developing a web application using ASP.NET Core 2.1. I want to override/localize default data-annotations' error messages without using any package and external dependency or even culture. For example this is Mymodel:
class Mymodel
{
[Required]
public string Email { get; set; }
}
When I submit the empty form it returns this default error:
The {0} field is required. (in this case {0}= Email)
is there anyway to override/customize/change this default error for all [Required] data-annotations??
I don't wanna add ErrorMessage to my required data-annotation. Like this:
class ViewModel
{
[Required(ErrorMessage = "my customized error message")
public string Email { get; set; }
}
Also I don't want to write my own data attribute.
I want something general. So wherever I use [Required] data-annotation, my customized error message will be shown.
I found this related question but it didn't helped me because no one answered the question.
How to provide localized validation messages for validation attributes
I checked Microsoft docs. It wasn't clear