繁体   English   中英

使用模型作为parmenter将操作重定向到其他区域中的操作

[英]Redirect action to action in other area with model as parmenter

我在管理区域现在想要将值发送到帐户控制器,这是我可以发送的默认区域

ChangePasswordModel mode = new ChangePasswordModel();
                mode.ConfirmPassword = password;
                mode.NewPassword = password;
                mode.OldPassword = user.Password;
                return RedirectToAction("ChangePassword", "Account",new { area = '/' } , new {model = mode});

这是我在帐户控制器中的其他操作,我想重定向我的代码

[Authorize]
        [HttpPost]
        public ActionResult ChangePassword(ChangePasswordModel model)
        {
            if (ModelState.IsValid)
            {

                // ChangePassword will throw an exception rather
                // than return false in certain failure scenarios.
                bool changePasswordSucceeded;
                try
                {
                    MembershipUser currentUser = Membership.GetUser(User.Identity.Name, true /* userIsOnline */);
                    changePasswordSucceeded = currentUser.ChangePassword(model.OldPassword, model.NewPassword);
                }
                catch (Exception)
                {
                    changePasswordSucceeded = false;
                }

                if (changePasswordSucceeded)
                {
                    return RedirectToAction("ChangePasswordSuccess");
                }
                else
                {
                    ModelState.AddModelError("", "The current password is incorrect or the new password is invalid.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }

RedirectToAction没有超载,需要4个参数

尝试这个:

return RedirectToAction(
    "ChangePassword",
    "Account",
     new { area = "", model = mode });
return RedirectToAction("ChangePassword", "Account",
    new { area = "other_area_name", model = mode });

@mattytommo的答案是正确的解决方案,4个参数没有重载方法。 我更新了我的答案。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM