简体   繁体   English

尝试创建X类型的控制器时发生错误。请确保该控制器具有无参数构造函数

[英]An error occurred when trying to create a controller of type X. Make sure that the controller has a parameterless constructor

I'm working on an asp.net mvc project where I've created a partial view with some dropdowns. 我正在一个asp.net mvc项目上,在其中创建了带有一些下拉菜单的局部视图。 These are populated with ajax, and should work as a filter. 这些用ajax填充,并且应该作为过滤器。 (Not really relevant to my question, I guess, but nice to know anyhow). (我想这与我的问题并不十分相关,但是很高兴知道)。

A problem occurrs when trying to invoke the partial view, saying the following: An error occurred when trying to create a controller of type 'Project.Name.Web.Controllers.PlanFilterController'. Make sure that the controller has a parameterless public constructor. 尝试调用部分视图An error occurred when trying to create a controller of type 'Project.Name.Web.Controllers.PlanFilterController'. Make sure that the controller has a parameterless public constructor.问题,并说以下内容: An error occurred when trying to create a controller of type 'Project.Name.Web.Controllers.PlanFilterController'. Make sure that the controller has a parameterless public constructor. An error occurred when trying to create a controller of type 'Project.Name.Web.Controllers.PlanFilterController'. Make sure that the controller has a parameterless public constructor.

However, my controller does appear to have a parameterless constructor; 但是,我的控制器似乎确实有一个无参数的构造函数。

public class PlanFilterController : BaseController
    {
        public PlanFilterControllerViewModel Model { get; set; }
        public List<DropDownItem> Items { get; set; }

        public List<ProjectContract> AllProjects { get; set; }
        public List<CustomerContract> AllCustomers { get; set; }
        public List<UnitContract> AllUnits { get; set; }

        private ProjectServiceClient ProjectClient { get; set; }
        private CustomerServiceClient CustomerClient { get; set; }

        public PlanFilterController()
        {
            AllProjects = new List<ProjectContract>();
            AllCustomers = new List<CustomerContract>();
            AllUnits = new List<UnitContract>();

            ProjectClient = new ProjectServiceClient();
            CustomerClient = new CustomerServiceClient();

            AllProjects = ProjectClient.GetProjects().ToList();
            AllCustomers = CustomerClient.GetCustomers().ToList();
            AllUnits = UnitClient.GetUnits(true, "", false).ToList();
        }

        // GET: /PlanFilter/
        [ChildActionOnly]
        public ActionResult FilterControl()
        {

            return PartialView();
        }

        // Populate dropdowns
        public JsonResult GetCascadeCustomers()
        {
            Items = new List<DropDownItem>();

            foreach (var customer in AllCustomers)
            {
                Items.Add(new DropDownItem
                {
                    ItemId = customer.Id,
                    ItemName = customer.Name
                });
            }

            return Json(Items, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetCascadeProjects()
        {
            Items = new List<DropDownItem>();

            foreach (var project in AllProjects)
            {
                Items.Add(new DropDownItem
                {
                    ItemId = project.Id,
                    ItemName = project.Name
                });
            }

            return Json(Items, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetCascadeUnits()
        {
            Items = new List<DropDownItem>();

            foreach (var unit in AllUnits)
            {
                Items.Add(new DropDownItem
                {
                    ItemId = unit.Id,
                    ItemName = unit.Name
                });
            }

            return Json(Items, JsonRequestBehavior.AllowGet);
        }
    }

What am I missing here? 我在这里想念什么? Also, if someone could please provide the explanation to why this is the case, that would be nice :) 另外,如果有人可以提供原因说明,那就太好了:)

As mentioned in comments, something had happened when I added my service references, and some code was not automatically generated. 如评论中所述,当我添加服务引用时发生了某些事情,并且没有自动生成一些代码。 This again caused the exception mentioned. 这再次引起了提到的异常。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试创建类型的控制器时发生错误。 确保控制器有一个无参数的公共构造函数 - An error occurred when trying to create a controller of type. Make sure that the controller has a parameterless public constructor 尝试创建“SaleController”类型的 controller 时发生错误。 确保 controller 有一个无参数的公共构造函数 - An error occurred when trying to create a controller of type 'SaleController'. Make sure that the controller has a parameterless public constructor 尝试创建“ XYZController”类型的控制器时发生错误。 确保控制器具有无参数的公共构造函数 - Error occurred when trying to create a controller of type 'XYZController'. Make sure controller has a parameterless public constructor “尝试创建类型为&#39;HomeController&#39;的控制器时发生错误。请确保该控制器具有无参数的公共构造函数 - "An error occurred when trying to create a controller of type 'HomeController'. Make sure that the controller has a parameterless public constructor 尝试创建“EmployeeController”类型的控制器时发生错误。 确保控制器具有无参数的公共构造函数 - Error occurred when trying to create a controller of type 'EmployeeController'. Make sure controller has a parameterless public constructor 尝试创建控制器时发生错误,请确保该控制器具有无参数的公共构造函数 - An error occurred when trying to create a controller, Make sure that the controller has a parameterless public constructor 确保控制器具有无参数的公共构造函数 - Make sure that the controller has a parameterless public constructor 确保控制器具有无参数的公共构造函数? - Make sure that the controller has a parameterless public constructor? 确保 controller 有无参数公共构造函数错误 - Make sure that the controller has a parameterless public constructor error WebApi引发错误-确保控制器具有无参数的公共构造函数 - WebApi is throwing error - Make sure that the controller has a parameterless public constructor
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM