Redirect an action to an action to another area using the model as a share

I am in the admin area now I want to send the values ​​to the Account Controller, which is in the default area, how can I send

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

this is my other action in Account Controller where I want to redirect my code

[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);
        }
+5
source share
2 answers

There is no overload for RedirectToActionwhich takes 4 parameters .

Try the following:

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

@Mattytommo's answer is the right solution, there is no overload method for 4 parameters. I updated my answer.

+3
source

All Articles