How to change PasswordValidator Properties error message in asp.net mvc identity 2

188 Views Asked by At

I have the following register action result post that automatically written by identity 2:

[HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    [Route("Register")]
    public async Task<ActionResult> Register(RegisterViewModel model)
    {
        if (ModelState.IsValid)
        {
            var user = new ApplicationUser { UserName = model.Email, Email = model.Email };
            var result = await UserManager.CreateAsync(user, model.Password);
            if (result.Succeeded)
            {
                var code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking this link: <a href=\"" + callbackUrl + "\">link</a>");
                ViewBag.Link = callbackUrl;
                return View("DisplayEmail");
            }
            //My problem is here
            AddErrors(result);
        }

        
        return PartialView(model);
    }

in above code(where I mark by comment) if something go wrong it will show me a specified error in English by AddError(Result); Method. Result type is IdentityResult.

this is AddError(Result); method:

private void AddErrors(IdentityResult error)
    {
        foreach (var Error in error.Errors)
        {
            ModelState.AddModelError("", Error);
        }
    }

I've search a lot but I just find error customization for Required and StringLength

enter image description here

my question: How can I change all this error message to language I want?

I'm so new in MVC; thanks for your easy solutions.

0

There are 0 best solutions below