2013-03-19 37 views
5

我在管理方面現在要發送的值來應對控制器,它是在默認區域,我怎麼可以把在其他領域的行動重定向動作與模型帕門

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

回答

4

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

試試這個:

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

+1。我沒有看到我的錯誤,你是對的。 – 2013-03-19 12:25:36

+0

ITs工作,但它重定向到[HttpGet]行動我想重定向到[Httppost]方法 – 2013-03-19 12:27:14

+0

@MoeezAgha沒有問題。你不能重定向到'HttpPost'動作,它必須是'HttpGet'。 – mattytommo 2013-03-19 12:29:59

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

@mattytommo的答案是正確的解決方案,對4個參數沒有重載方法。我更新了我的答案。

+0

我應該怎麼做,如果它是默認的區域 – 2013-03-19 12:13:34

+0

就寫什麼的區域這樣的'新{面積=「」}' – 2013-03-19 12:15:46

+0

它不工作 – 2013-03-19 12:16:10