Open Closed

How can I do to use different languages ​​in the validation of my error messages through DataAnotation? i am using Suite Version 4.4.2 #2885


User avatar
0
arodriguez created

Greetings, I am using the following regular expression:

[RegularExpression(@"^[a-zA-Z0-9]+$", ErrorMessage ="El código solo puede contener letras y Números")]

I need the error message to be customized and related to a tag used within the Json files of the Localization For example something like this:

[RegularExpression(@"^[a-zA-Z0-9]+$", ErrorMessageResourceName ="CodeMessage")] // CodeMessage is my Generic Tag into es.json and en.json (both located in the localization folder)

  • ABP Framework version: v4.4.2
  • UI type: Blazor
  • DB provider: Sql Server

1 Answer(s)
  • User Avatar
    0
    EngincanV created
    Support Team .NET Developer

    Hi, can you configure the AbpMvcDataAnnotationsLocalizationOptions in your module class as below:

    [DependsOn(
        //modules...
    )]
    public class MyBlazorModule : AbpModule
    {
        public override void PreConfigureServices(ServiceConfigurationContext context)
        {
            context.Services.PreConfigure<AbpMvcDataAnnotationsLocalizationOptions>(options =>
            {
                options.AddAssemblyResource(typeof(MyResource), typeof(MyBlazorModule).Assembly);
            });
        }
    }
    

    Then you should be able to get the error messages as localized.

Learn More, Pay Less
33% OFF
All Trainings!
Get Your Deal
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.2.0-preview. Updated on January 09, 2026, 07:22
1
ABP Assistant
🔐 You need to be logged in to use the chatbot. Please log in first.