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条回答
可以哭但决不认输i
2楼-- · 2019-01-23 12:09

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.
查看更多
再贱就再见
3楼-- · 2019-01-23 12:13

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.

查看更多
干净又极端
4楼-- · 2019-01-23 12:13

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 = "" });

查看更多
男人必须洒脱
5楼-- · 2019-01-23 12:20

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.
}
查看更多
做个烂人
6楼-- · 2019-01-23 12:29

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!

查看更多
兄弟一词,经得起流年.
7楼-- · 2019-01-23 12:30

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.

查看更多
登录 后发表回答