Question

I got an action List

    //[HttpGet] (will come back to that!)
    public ViewResult List(int page = 1)
    {
        //blah blah blah
        return View(viewModel);
    }

In its view we render action:

@{        
    Html.RenderAction("UpdateSearch");
}

Action definitions:

[ChildActionOnly]
[HttpGet]
public PartialViewResult UpdateSearch()
{
    // do something and display a form in view
    return PartialView(so);
}

[HttpPost]
public RedirectToRouteResult UpdateSearch(Options searchOptions)
{
    // do something and redirect to List
    return RedirectToAction("List");
}

and I'm getting: Child actions are not allowed to perform redirect actions exception every time someone submits the form. I'm new to MVC3, but it looks like the redirection is also a POST, because if [HttpGet] above List method is uncommented "the resource cannot be found" happens.

How do I change Http method on redirection or am I doing something wrong? I did try to Bing it, but no success.

Was it helpful?

Solution

The redirect info is stored in response header. However, the response is already being sent when child action is run so headers can't be written.

In short, there's no way of performing a redirect from child action other than through the use of javascript on client side.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top