2013-01-01 8 views
7

私は2つのコントローラ、SearchControllerDetailsControllerを持っています。mvc4で別のコントローラのビューを呼び出す方法

SearchControllerには、フォームを含む2つのビューが含まれています。この可能性は

私はSearchController

での私の見解の[HttpPost]アクションの詳細コントローラのビューにリダイレクトするようにしたいです?

+0

あなたは[RedirectResult](http://msdn.microsoft.com/en-us/library/systemを返すことを意味します。 web.mvc.redirectresult(v = 1010).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(); 
     } 
} 
関連する問題