tags:

views:

37

answers:

2

I have a partial control formy.ascx that I am using on a lot of pages that contains a form.

When I click submit on the partial control, following function handles the form submission.

[ActionName("FormyTemp"), AcceptVerbs(HttpVerbs.Post)]
public ActionResult FormyTemp(FormCollection result)

Now, I need to know what page i.e. action I was on when this form was submitted.

I tried passing (string)ViewContext.RouteData.Values["action"] as one of the form parameters, but it's telling Formy as the action when that is just a partial control. How should I go about doing this? I can't just look at the URL because some of my URL's are like domain.com/actionName and some of them are like domain.com/controllerName/actionName.

Also, please don't tell me to use RenderPartial...I need to use RenderAction

A: 

When rendering the action:

<% Html.RenderAction("Formy", new RouteValueDictionary { 
    { "ParentAction", ViewContext.RouteData.Values["action"] } 
}); %>

and the Formy action:

[ChildActionOnly]
public ActionResult Formy(string parentAction)
{
    // the parentAction parameter will have the desired value,
    // so you can pass it to the view model Formy.ascx is strongly
    // typed to and include it as hidden field in the form. When
    // the form is later submitted the value will be passed to FormyTemp
    return View();
}
Darin Dimitrov
A: 

From my understanding, you need to know the action of the Parent form, not the individual RenderAction that rendered the partial. In that case you can use the following:

ViewContext.ParentActionViewContext.RouteData.Values["action"];
Clicktricity