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
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
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 requiredI want to change that
LastNametoLast NameIs there any data attribute to set to the property to tell ABP to show
Last Nameas the display name for that property?Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
try DisplayName
[DisplayName("Last Name")] [Required] public string LastName { get; set; }Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
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
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
The DisplayName Attribute could work, but how do I hook it up with the ABP Localization source? Does
AbpDisplayNameAttributework for this?Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Nope.
AbpDisplayNameis only used in Razor page.Use case:
@Model.LabelFor(x => x.LastName)Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)