0

The Problem with this class:

public class ApplicationVM
{
    public int Id { get; set; }
    public string ApplicantFullName { get; set; }

    public DateTime DateOfCreation { get; set; }

    public DateTime? DateOfSent { get; set; }

    public int NumberOfDays { get; set; }

    public ApplicationTypeVM Type { get; set; }
    public ApplicationStatusVM Status { get; set; }

    [Required(ErrorMessage = "StatedDates required")]
    [RegularExpression(@"^((?:^|\s*)\d{2}\.\d{2}\.\d{4})*$", ErrorMessage = "StatedDates invalid")]
    public string StatedDates { get; set; }

    [UIHint("CoordinatorEditor")]
    [Required(ErrorMessage = "Coordinator required")]
    public string CoordinatorFullName { get; set; }

    public string Comment { get; set; }
}

Data annotations error messages don't localize. I inherit this class for other view models which are used on UI. For example, this one:

public class RemoteWorkingApplicationVM : ApplicationVM
{
    [Required(ErrorMessage = "WorkingPlan required")]
    public List<ActivityVM> WorkingPlan { get; } = new List<ActivityVM>();
}

Other localization is working. I think the problem is with inheritance. What do you think?

Aliensis
  • 85
  • 1
  • 8
  • maybe you are missing ```.AddDataAnnotationsLocalization()``` after .AddRazorPages() or .AddMvc() – spzvtbg Jun 06 '22 at 14:45
  • I think this answer may help:https://stackoverflow.com/questions/40828570/asp-net-core-model-binding-error-messages-localization – Tiny Wang Jun 07 '22 at 02:57

1 Answers1

0

My thoughts were correct, the problem was with the inheritance. In my case, I needed to add entries for data annotation messages in resources for all supertype view models.

Aliensis
  • 85
  • 1
  • 8