2009-06-30 54 views
2

我使用RenderAction渲染全局使用的部分。RenderAction需要表現不同,具體取決於包含頁面

這是用戶可以搜索實體的部分。它取決於控制器/操作,它使父主視圖一旦找到實體就完成了什麼。

可以說我有控制器:

HireController,FireController與 行動ActOnPerson和

與行動是FindPerson把PeopleController這使得局部 是FindPerson

的意見是租金/ SearchPerson.aspx and Fire/SearchPerson.aspx

每個視圖包含助手:

<%Html.RenderAction("FindPerson ", "People"); %> 

該職位,以HireController/FireController包含在局部形式。 它需要這樣,因爲實際上有幾個步驟(表單帖子)涉及找到一個人。

如果需要將表單發佈到FireController或HireController,有沒有辦法在部分FindPerson中決定?我想我正在尋找像WebControls的公共屬性,但對於RenderAction。

回答

2

只需添加參數( 「PostTo」 或 「下一頁」),以People.FindPerson行動:

<% Html.RenderAction("FindPerson ", "People", new { next = Url.Action("ActOnPerson", "HireController") }); %> 

<!-- or --> 

<% Html.RenderAction("FindPerson ", "People", new { nextaction = "ActOnPerson", nextcontroller = "HireController" }); %> 

在是FindPerson PartialView:

<form method="post" action="<%= ViewData["next"].ToString() %>"> 

<!-- or --> 

<% using (Html.BeginForm(
    ViewData["nextaction"].ToString(), ViewData["nextcontroller"].ToString()) { %> 
相關問題