Simply Change culture for [Required] data annotation validation message in .net Core 6.0
07:21 18 Nov 2022

What I'm trying to do seems really simple but I'm struggling with it since this morning...

I just want to force French language for html.ValidationMessageFor(x=>x.Name)

Here my name property :

[Required]
public string Name { get; set; }

Right now, if I try to validate a form without filling the property I've got the "The Name field is required."

  1. Where does this message "The {0} is required." come from ?

  2. How can I change the language of it without having to override all my [Required] properties in all my ViewModels with something like :

[Required(ErrorMessageResourceName ="Required",ErrorMessageResourceType =typeof(FrenchDataAnnotation))]

Thanks a lot.

asp.net-core data-annotations asp.net-core-localization