How to change default error messages for MVC Core ValidationSummary?

Using MVC Core with ASP.NET ID I would like to change the default error messages for ValidationSummary that were obtained from the Register action. Any advice would be highly appreciated.

ASP.NET Core Register Action

+7
asp.net-mvc asp.net-core asp.net-identity
source share
2 answers

You must override the IdentityErrorDescriber methods to modify the error messages.

 public class YourIdentityErrorDescriber : IdentityErrorDescriber { public override IdentityError PasswordRequiresUpper() { return new IdentityError { Code = nameof(PasswordRequiresUpper), Description = "<your error message>" }; } //... other methods } 

In Startup.cs set IdentityErrorDescriber

 public void ConfigureServices(IServiceCollection services) { // ... services.AddIdentity<ApplicationUser, IdentityRole>() .AddErrorDescriber<YourIdentityErrorDescriber>(); } 

Reply from fooobar.com/questions/136795 / ...

+7
source share

You can use DataAnnotations in your RegisterViewModel class. In fact, if you raise your application using authentication, you will get something like this:

  [Required] [EmailAddress] [Display(Name = "Email")] public string Email { get; set; } [Required] [StringLength(100, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 6)] [DataType(DataType.Password)] [Display(Name = "Password")] public string Password { get; set; } [DataType(DataType.Password)] [Display(Name = "Confirm password")] [Compare("Password", ErrorMessage = "The password and confirmation password do not match.")] public string ConfirmPassword { get; set; } 

Obviously, you can change ErrorMessage to whatever you want!

-one
source share

All Articles