Error executing child request for handler in view

2019-01-23 11: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?

11条回答
劳资没心,怎么记你
2楼-- · 2019-01-23 12:31

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

查看更多
孤傲高冷的网名
3楼-- · 2019-01-23 12:31

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.

查看更多
该账号已被封号
4楼-- · 2019-01-23 12:32

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.

查看更多
虎瘦雄心在
5楼-- · 2019-01-23 12:34

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.

查看更多
The star\"
6楼-- · 2019-01-23 12:34

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

查看更多
登录 后发表回答