2013-01-01 131 views
7

我有2個控制器,SearchControllerDetailsController如何在mvc4中調用另一個控制器的視圖

SearchController包含2個視圖,其中包含表單。

我想重定向到的細節控制器的看法對我的看法在SearchController

[HttpPost]行動這是可能的???

+0

您通過返回[RedirectResult]的意思(http://msdn.microsoft.com/en-us/library/system。 web.mvc.redirectresult(v = vs.108)的.aspx)? – rene

回答

6

如果您正在第一個控制器中執行一些處理,然後將結果發送到另一個控制器,則可以嘗試RedirectToAction

查看

using(@Html.BeginForm("firstaction", "search", FormMethod.Post)){ 

    // form stuff 
} 

控制器

public class SearchController 
{ 

     [HttpPost] 
     public ActionResult FirstAction() 
     { 
      // do initial processing in the first controller 
      // e.g persisting changed on Edit Screen 

      return RedirectToAction("SecondAction","Details"); 

     } 
} 

public class DetailsController 
{ 
    public ActionResult SecondAction() 
     { 
      // do remaining processing in the first controller 
      // fetching data for a grid and displaying the grid of items 

      return View(); 
     } 
} 
相關問題