Alireza
Alireza

Reputation: 1

Using asp.net localization for view models error messages

I'm trying to create multilanguage web app in asp.net razor pages. I have 2 .resx files : App.Endpoints.RazorPages.UI\Resources\Areas\Account\Pages\SignUp.fa.resx & SignUp.en.resx

and my Singup page is in : App.Endpoints.RazorPages.UI\Areas\Account\Pages\SignUp.cshtml.cs

and my view model is in App.Endpoints.RazorPages.UI\ViewModels

 public class SignUpVM
 {
     [Required(ErrorMessageResourceName = "username_required", ErrorMessageResourceType = typeof(Resources))]
     [StringLength(32)]
     public string UserName { get; set; }

...

my problem is I have an error on Resources : typeof(Resources) because of 'Resources' is inaccessible due to its protection level. and this class is from Microsoft.AspNetCore.Hosting and it's embedded and I can't change it (I must use this class ?) also my .resx files access level is public.

what should I do to solve this error or is there any other way to use localization for error messages?

Upvotes: 0

Views: 103

Answers (0)

Related Questions