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.
AddModelError() method. The ValidationSummary() method will automatically display all the error messages added in the ModelState . Thus, you can use the ValidationSummary helper method to display error messages.
In order for the Validator 's error message to display in the ValidationSummary , you need to set the Validator s Display="none" .
ASP.NET MVC: ValidationSummary The ValidationSummary() extension method displays a summary of all validation errors on a web page as an unordered list element. It can also be used to display custom error messages.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With