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

时间:2013-03-19 12:05:01

标签: c# asp.net-mvc asp.net-mvc-3

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

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

2 个答案:

答案 0 :(得分:4)

<强> There isn't an overload for RedirectToAction that takes 4 parameters

试试这个:

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

答案 1 :(得分:3)

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

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