Get The Parent Controller from a PartialView Action

545 Views Asked by At

I have a _Partial.cshtml view which is called in a Parent.cshtml view in the following manner:

Parent.cshtml:

@Html.Render("_Partial");

In the _Partial.cshtml view, there is a button which is linked to a form in the following manner:

using (Html.BeginForm("Send", "DetailsController", FormMethod.Get))
{
    <input type="submit" value="submit" />
}

In the DetailsController I have the Send action which looks like this:

    public ActionResult Send(int orderId)
    {
        if (some condition)
        {
            return RedirectToAction(parentAction, parentController, new {orderId});
        }

      return RedirectToAction(action, controller, new {orderId});
    }

The issue I am having is that the ParentActionViewContext is null.

How can I obtain the Parent Controller name of the partial view?

1

There are 1 best solutions below

0
On

I believe this is used for Parent/Child actions... not view partials. The only time this is not null is when you are in a child action.