Error executing child request for handler in view

后端 未结 12 917
臣服心动
臣服心动 2020-12-09 02:30

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

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


        
相关标签:
12条回答
  • 2020-12-09 03:15

    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.

    0 讨论(0)
  • 2020-12-09 03:15

    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.
    }
    
    0 讨论(0)
  • 2020-12-09 03:22

    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.
    
    0 讨论(0)
  • 2020-12-09 03:22

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

    0 讨论(0)
  • 2020-12-09 03:24

    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.

    0 讨论(0)
  • 2020-12-09 03:25

    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!

    0 讨论(0)
提交回复
热议问题