Search code examples
c#asp.net-mvcasp.net-mvc-4partial-views

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


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?


Solution

  • 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.