MVC 1.0.1更改密码

时间:2018-08-06 16:20:47

标签: c# asp.net-mvc

这是我的帐户控制者,当我单击“更改密码”时,没有任何反应。我的编码有问题吗?

[HttpPost]
    public async Task<IActionResult> ChangePassword(ChangePasswordVM changePasswordVM, string returnUrl = null)
    {
        ApplicationUser _User = await _userManager.GetUserAsync(User);
        if (ModelState.IsValid)
        {
            var result = await _userManager.ChangePasswordAsync(_User, changePasswordVM.CurrentPassword, changePasswordVM.NewPassword);
            if (result.Succeeded)
            {
                if (returnUrl == null)
                    return RedirectToAction("Index", "Home");
                else
                    return LocalRedirect(returnUrl);
            }
            ModelState.AddModelError("", "Invalid Password Change Attempt.");
        }
        return View();
    }

1 个答案:

答案 0 :(得分:-2)

 [HttpPost]
    public async Task<IActionResult> ChangePassword(ChangePasswordVM changePasswordVM, string returnUrl = null)
    {
        LeaveUser _User = await _userManager.GetUserAsync(User);
        if (ModelState.IsValid)
        {
            if (changePasswordVM.NewPassword == changePasswordVM.ConfirmNewPassword)
            {
                var result = await _userManager.ChangePasswordAsync(_User, changePasswordVM.CurrentPassword, changePasswordVM.NewPassword);
                if (result.Succeeded)
                {
                    if (returnUrl == null)
                        return RedirectToAction("Index", "Home");
                    else
                        return LocalRedirect(returnUrl);
                }
            }
            else
            {
                ModelState.AddModelError("", "Invalid Password Change Attempt. Password must be at least 8 characters.");
            }
        }
        return View();