Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect action to action in other area with model as parmenter

I am on Admin area now want to send the values to Account Controller which is in default area how i can 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);
        }
like image 911
Moeez Agha Avatar asked Mar 19 '13 12:03

Moeez Agha


2 Answers

There isn't an overload for RedirectToAction that takes 4 parameters.

Try this:

return RedirectToAction(
    "ChangePassword",
    "Account",
     new { area = "", model = mode });
like image 150
mattytommo Avatar answered Oct 24 '22 03:10

mattytommo


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.

like image 44
AliRıza Adıyahşi Avatar answered Oct 24 '22 02:10

AliRıza Adıyahşi