AG70
AG70

Reputation: 976

How to change default error messages of MVC Core ValidationSummary?

Using MVC Core with ASP.NET Identity I would like to change the defaults error messages of ValidationSummary that arrived from Register action. Any advice will be much appreciated.

ASP.NET Core Register Action

Upvotes: 8

Views: 5335

Answers (1)

adem caglin
adem caglin

Reputation: 24073

You should override methods of IdentityErrorDescriber to change identity 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>();
}

The answer is from https://stackoverflow.com/a/38199890/5426333

Upvotes: 17

Related Questions