Error executing child request for handler in view
Asked Answered
T

13

35

I have an MVC 4 view where I render the following actions

@{
    Html.RenderAction("Index", "Logo");
    Html.RenderAction("Index", "MainMenu");
}

I have a form on my view which is filled out and posted to the controller. In the controller I perform some tasks and then send the model back to my view

[HttpPost]
public ActionResult Index(ManageAdministratorModel manageAdministratorModel)
{
     // I save some of the fields to the database here.
     return View(manageAdministratorModel);
}

When I'm redirected to the view I receive the following error

Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.

on this line

Html.RenderAction("Index", "Logo");

Any idea why this is happening?

Tanh answered 9/10, 2013 at 12:57 Comment(1)
Top Tip: Error messages work better as quotes, rather than code blocks (my edit)Jason
T
38

Ok I found the problem, hopefully this will help someone in future.

The controllers for the partial views each contained the [HttpGet] attribute. For example

[HttpGet]
public ActionResult Index()
{
}

I remove the attribute from both controllers

public ActionResult Index()
{
}

and everything is now working.

Tanh answered 9/10, 2013 at 14:8 Comment(5)
Nice. I came across a similar problem which was solved using this information.Kathikathiawar
thx alot you saved my time ..i kept [HttpPost] . i removed it now its workingDonndonna
for people who want to know the difference, one can be System.Web.Http and the over can be System.Web.MvcBarnaby
Still I am getting the same issue, even if I remove.Scutellation
Solved ! Thanks !Companionable
R
28

I just got this error occurring in my razor when my partial view had a code formatting error in it.

If you click 'Continue' to get past the error, you'll see the actual error message displayed in the browser window that you loaded it from.

Correct the error in the partial view and it'll work!

Reduplication answered 19/12, 2014 at 16:27 Comment(2)
This helped me, I was trying to add css and script parts in the partial which it did not like. Tanks @ReduplicationKimble
For me, it was a missing reference in the project. I opened each .cshtml file to see if there are errors inside, then I found the @using calling to a namespace in a DLL that wasn't referenced.Dup
I
9

Replace:

return View(manageAdministratorModel);

with:

return PartialView(manageAdministratorModel);

otherwise you might be ending in an infinite loop because you are rendering a view which is attempting to render a view which is attempting to render a view, ...

Also you might need to remove the [HttpPost] attribute from your child action.

Intersection answered 9/10, 2013 at 13:5 Comment(5)
Oh wait. Your controller action is decorated with the [HttpPost] attribute. Get rid of it. For child actions there shouldn't be such attribute.Intersection
When I remove the [HttpPost] attribute and add the [ChildActionOnly] attribute I'm getting an "The action 'Index' is accessible only by a child request." error.Tanh
Oh I misread.. Ignore my comment, remove the [ChildActionOnly] attribute.Waldenburg
Ok found the problem. Will post below to clarify.Tanh
I have replace with the partial view and removed all the attributes. Still I am getting the issue. I am ending up with the infinite loop. How to solve this issue?Scutellation
H
2

The example of "Child Action Only" is:

     public class FiltersController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }

        [ChildActionOnly]
        public ActionResult Departments()
        {
            string s = "Mahi and kallu";
            return View(s);
        }

    }

**for this am creating 2 views** 
1) Index:

    <html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Index</title>
</head>
<body>
    <div>
         @Html.Partial("Departments","Filters")

</body>
</html>
**and for Departments View:**
<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>Departments</title>
</head>
<body>
    <div>
       @Model      
    </div>
</body>
</html>


the ***childactions*** can be rendered with the help of "Partial" keyword.
Herbart answered 16/10, 2015 at 12:17 Comment(0)
H
2

I had the same error. It began when I changed an action to another controller, so when running the program couldn't find the view in the folder. So if you move an action to another controller, also move the view to the respective folder's controller.

Hengel answered 12/5, 2016 at 14:34 Comment(0)
D
2

Get rid of the layout @{ Layout = null; } in the child view.

Dandruff answered 30/7, 2016 at 22:25 Comment(1)
This actually helped me, I had Layout = null in my partialview which caused this error.Bub
B
2

I was facing the same issue but I put [HTTPGet] attribute over the function name and it worked for me.

[HttpGet]
//for Filter parital view
[ChildActionOnly]
public ActionResult Filter()
{ 
  // Your code will come here.
}
Brainwork answered 15/10, 2016 at 5:58 Comment(0)
P
1

I had exactly the same problem, and because I was using attribute routing, the inner exception error message was:

No matching action was found on controller ''. 
This can happen when a controller uses RouteAttribute for routing, 
but no action on that controller matches the request.

Remove the [HttpGet] attributes from action methods called by Html.Action() and it works. Nothing to do with routing.

Plunk answered 20/10, 2015 at 21:48 Comment(0)
P
1

I got this error, but my problem was diferent. To see what is the error about, involve the line you get the error inside a try catch code, like this:

 try 
    {           
         @Html.RenderAction("Index", "Logo", new {id = Model.id});
    }
    catch (Exception e)
    {
        throw;
    }    

Execute it with a break point at throw line and check the inner exception of the 'e'. My problem was that I'd changed the parameter name on my Controller and forgot to change it on my View.

It's easier to get the error using try catch.

Paleography answered 29/7, 2016 at 16:31 Comment(0)
T
1

I had this problem, It could happen because render engine can't find any view (corresponding to the name that is given in acton) I'd given wrong name of view (I mistakenly had given action name instead of view name) when I return view name and view model using PartialView() method, I corrected my view name and it worked fine

Tee answered 7/2, 2017 at 6:53 Comment(0)
D
1

This happened to me, because I was calling the view from different areas.

The view I wanted to call was not within an area, so when calling it from outside of all areas a call like

@Html.RenderAction("Index", "Logo");

would work without problems.

But when I wanted that same view called from another view that was inside an area, I would have to add some additional information to the call to make it explicit:

@Html.RenderAction("Index", "Logo", new { area = "" });

Darius answered 20/3, 2018 at 10:38 Comment(0)
S
0

In my case, I added the following code into Global.asax.cs:

protected void Application_Error(object sender, EventArgs e)
{
    var ex = Server.GetLastError();
    ...
}

Then I added a break point there and see the ex's InnerException is the SQL DB Connection error. So I replaced my Web.config file with my local development one with the correct connection string, and the problem is gone.

Stultify answered 29/9, 2019 at 19:57 Comment(0)
E
0

I was getting this error from dns forwarding on www.mydomain.com to mydomain.com

Error executing child request for handler 'System.Web.Mvc.HttpHandlerUtil+ServerExecuteHttpHandlerAsyncWrapper'.

The only solution I've found is to hide it from logs since it was flooding the logs making them harder to use and find the real errors. If you know how to solve this better please let know.

To hide from logs I do:

var details ="";

if (HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)?.IndexOf("www.mydomain.com") != -1) 
    details = "dnsforwarding";

if (HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Authority)?.IndexOf("localhost") != -1) 
    details = "devenv";

if(details != "devenv" && details != "dnsforwarding")
    LogMessage(ex.Message, details, messageType, messageSeverity);
Englishism answered 9/11, 2023 at 15:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.