Error executing child request for handler - Partial View Called From Controller

久未见 提交于 2019-12-12 13:09:40

问题


I have a method in my Home Controller that returns a partial view, but when I run my application I get the error.

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

The Method in my controller gets the model and returns the partial view.

public PartialViewResult _GetToDo()
        {
            using (KnightOwlContext db = new KnightOwlContext())
            {
                var todoList = new List<ViewModels.ToDo>();
                DashboardHelper dashHelper = new DashboardHelper(db);

                var results = dashHelper.GetToDoList(StaffId);

                foreach(var r in results)
                {
                    todoList.Add(new ViewModels.ToDo()
                    {
                        ToDoId = r.ToDoId,
                        Complete = r.Complete,
                        Date = r.Date,
                        Priority = GetPriority(r.Priority),
                        StaffId = r.StaffId,
                        Text = r.Text
                    });
                }

                return PartialView("_ToDo", todoList);
            }
        }

And I call this method in my View:

@Html.Action("_GetToDo", "Home")

The method is in my 'Home Controller' and the Partial View is called from Views > Home > Index

So far I've tried Html.Partial and Html.RenderPartial and neither of those work either with a different error message. I'm completely at a loss as to how to return the partial view, what is it I'm doing wrong?


回答1:


During _ToDo view creation tick the checkbox Create as Partal View. If you create your partial view referencing your layout page, then you will get in an infinite loop, executing your layout page over and over.



来源:https://stackoverflow.com/questions/37264189/error-executing-child-request-for-handler-partial-view-called-from-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!