2016-08-16 6 views
7

ASP.NET IDでMVCコアを使用するRegisterアクションから到着したValidationSummaryのデフォルトエラーメッセージを変更したいと思います。 アドバイスをいただければ幸いです。MVC Core ValidationSummaryのデフォルトのエラーメッセージを変更するには?

ASP.NET Core Register Action

+0

からであるあなたがしてAccountViewModel.csにこれらのエラーメッセージを変更することができるはず – Vipul

+0

あなたはモデルクラスからこのメッセージを変更することができますIdentityErrorDescriber

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

を設定DataAnnotationのプロパティ 'ErrorMessage =" ... "' –

答えて

7

IDエラーメッセージを変更するには、IdentityErrorDescriberのメソッドをオーバーライドする必要があります。 Startup.cs

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

答えはhttps://stackoverflow.com/a/38199890/5426333

-1

あなたのRegisterViewModelクラスでDataAnnotationsを使用することができます。あなたが認証を使用してアプリケーションを足場場合は実際には、あなたはこのような何かを得るでしょう:

[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; } 

を明らかに、あなたはそれになりたいものにErrorMessageを変更することができます!

+0

FelixがDataAnnotationsを変更しても、Validation Summaryには影響しません。 – AG70

関連する問題