I'm using ASP.NET Core, and trying to localize the application. I managed to use new asp .net core resources to localize controllers and views, and old resources to localize error messages for model validation.
However, when the error message is not linked to a model field annotation (like "Required") and the data for model binding is incorrect (like a text where a number is expected), I receive the error like below, which I'm unable to localize:
"The value 'abc' is not valid for ID."
When I enter abc
for ID
property in View
, since the model binding can not be done to the field and it shows a validation message near the field, saying "The value 'abc' is not valid for ID.". Here is the class I'm using:
public class Country : IHasID
{
public int ID { get; set; }
[Required(ErrorMessageResourceType = typeof(L.Val),
ErrorMessageResourceName = "NameR")]
[MaxLength(100, ErrorMessageResourceType = typeof(L.Val),
ErrorMessageResourceName = "Max")]
public string Name { get; set; }
/*Some other properties*/
}
The similar issues I found on the internet were either targeted to older asp .net version, or else didn't help me solve the problem.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…