When I get UserFriendlyExceptions related to DTO Validation (AbpValidationException) the exception message detailing the properties with errors display the property name as defined in the DTO class.
Is there any way to set a localized display name for those properties so the error messages the users can get are more clear about what fields have errors?
6 Answer(s)
-
0
see:https://github.com/aspnetboilerplate/aspnetboilerplate/issues/1360
-
0
I think that's not exactly what I'm talking about.
Look at this example.
public class RegisterInput { [Required] public string FirstName { get; set; } [Required] public string LastName { get; set; } }
Using that DTO with validation and provide this JSON to the app service:
{ firstName: "Emiliano", lastName: null }
Then I will end up with an exception with a message like
The field LastName is required
I want to change that
LastName
toLast Name
Is there any data attribute to set to the property to tell ABP to show
Last Name
as the display name for that property? -
0
try DisplayName
[DisplayName("Last Name")] [Required] public string LastName { get; set; }
-
0
Hi, most of the model validation attributes came from asp.net core. Abp only collect all the validations from those attributes and put the errors in AbpValidationException
you can do something similar to this:
[Required(ErrorMessage = "Last Name is required")] public string LastName {get;set;}
Otherwise you can try using Abp Custom Validation instead
-
0
The DisplayName Attribute could work, but how do I hook it up with the ABP Localization source? Does
AbpDisplayNameAttribute
work for this? -
0
Nope.
AbpDisplayName
is only used in Razor page.Use case:
@Model.LabelFor(x => x.LastName)