I use DataAnnotation for validating models in ASP.NET Core. But when I have a required field, I got the error message in english when its missing like in this example:
class MyModel {
[Required]
[Display(Name = "Seitentitel")]
public string Title {get;set;}
}
This gave me a denglish the validation error message The Seitentitel field is required. But I want to have the message in a specific language, in this case for german. I would like to avoid setting the ErrorMessage
for each required attribute of my model. The default error message is fine in most cases, but in the wrong language.
How can I set the language for those validation messages?
I tried this one without success:
var supportedCultures = new[] { new CultureInfo("de-DE") };
app.UseRequestLocalization(new RequestLocalizationOptions {
DefaultRequestCulture = new RequestCulture("de-DE"),
SupportedCultures = supportedCultures,
SupportedUICultures = supportedCultures
});
If ASP.NET Core doesn't provide those translation, I need something like this: https://stackoverflow.com/a/38199890/5426333 But not for ASP.NET Core Identity, instead for the generic validation messages like in this case when a required-field is missing.