0

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.😊

4

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.