tags:

views:

76

answers:

1

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.

+2  A: 

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() ) { %>
eu-ge-ne