执行处理程序的子请求时出错-从控制器调用的局部视图 [英] Error executing child request for handler - Partial View Called From Controller

查看:94
本文介绍了执行处理程序的子请求时出错-从控制器调用的局部视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Home Controller中有一个返回部分视图的方法,但是当我运行应用程序时出现错误.

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

执行处理程序'System.Web.Mvc.HttpHandlerUtil + ServerExecuteHttpHandlerAsyncWrapper'的子请求时出错.

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

到目前为止,我已经尝试过Html.Partial和Html.RenderPartial,但它们都不能使用不同的错误消息.我对如何返回局部视图完全不知所措,这是我做错了什么?

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?

推荐答案

在_ToDo视图创建期间,选中创建为部分视图"复选框.如果创建引用布局页面的局部视图,则将陷入无限循环,一遍又一遍地执行布局页面.

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.

这篇关于执行处理程序的子请求时出错-从控制器调用的局部视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆