如何更改MVC Core ValidationSummary的默认错误消息? [英] How to change default error messages of MVC Core ValidationSummary?

查看:80
本文介绍了如何更改MVC Core ValidationSummary的默认错误消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将MVC Core与ASP.NET Identity结合使用我想更改从Register操作到达的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.

推荐答案

您应覆盖IdentityErrorDescriber的方法以更改身份错误消息.

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
}

Startup.cs中设置IdentityErrorDescriber

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

答案来自 https://stackoverflow.com/a/38199890/5426333

这篇关于如何更改MVC Core ValidationSummary的默认错误消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆