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.

Made with ❤️ on ABP v9.1.0-preview. Updated on December 10, 2024, 06:38