RenderAction needs to behave different depending on containing page

I use RenderAction to render a partial that is used all over my site.

It is a partial where the user can search for an entity. It depends on the Controller / Action that rendered the parent main view what is done once the entity is found.

Lets say I have the controllers:

HireController, FireController with Action ActOnPerson and

PeopleController with Action FindPerson which renders the partial FindPerson

The Views are Hire/SearchPerson.aspx and Fire/SearchPerson.aspx

Each View contains the helper:

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

The form that posts to HireController/FireController is contained in the partial. It needs to be this way, because there are actually a couple of steps (form posts) involved in finding a person.

Is there a way to decide inside the partial FindPerson if the form needs to be posted to FireController or HireController? I guess I am looking for something like public properties of WebControls but for RenderAction.


Just add parameter ("PostTo" or "Next") to People.FindPerson Action:

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

<!-- or -->

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

In FindPerson PartialView:

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

<!-- or -->

<% using (Html.BeginForm(
    ViewData["nextaction"].ToString(), ViewData["nextcontroller"].ToString() ) { %>
链接地址: http://www.djcxy.com/p/50940.html

上一篇: 我如何在不同的控制器中管理MVC区域和RenderAction?

下一篇: 根据包含页面,RenderAction需要表现不同