简体   繁体   English

MVC'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'中找不到任何构造函数

[英]MVC None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'

When I try to run MVC I get the following error: 当我尝试运行MVC时,出现以下错误:

None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 'A105004P.Controllers.AssessPersonController' can be invoked with the available services and parameters: Cannot resolve parameter 'Library.Interface.IAssessPerson AssessPerson' of constructor 'Void .ctor(Library.Interface.IAssessPerson)'. 无法使用可用的服务和参数调用类型为“ A105004P.Controllers.AssessPersonController”的,通过“ Autofac.Core.Activators.Reflection.DefaultConstructorFinder”找到的构造函数:无法解析构造函数“ Void .ctor(Library.Interface.IAssessPerson)'。

Here are the relevant files: 以下是相关文件:

ISYM.cs ISYM.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Library.Interface
{
    public interface ISYM
    {
        int id { get; set; }
        string ass_name { get; set; }
        string unitname { get; set; }
        string jobtitle { get; set; }
        string phone { get; set; }
        string faxphone { get; set; }
        string email { get; set; }
        string gender { get; set; }
        string servicestate { get; set; }
        string highestedu { get; set; }
        string mainexp { get; set; }
        string address { get; set; }
        string joinyears { get; set; }
        string picfile { get; set; }
        string memo { get; set; }
        bool enable { get; set; }
        string creuser { get; set; }
        System.DateTime credate { get; set; }
        string edituser { get; set; }
        System.DateTime editdate { get; set; }
        string tel { get; set; }
        void add();
        void edit();
        void delete();
        //IQueryable<ISYM> GetAll();
        IList<ISYM> getDataList();
       ISYM getSYMId(int? RoleId);
    }
}

SYMController SYMController

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Net;
using System.Web;
using System.Web.Mvc;
using FUN2012.Models;
using Library.EFClass;
using Library.Interface;
using Model;

namespace FUN2012.Controllers
{
    public class SYMController : Controller
    {
        ISYM _ap;

        public SYMController(ISYM SYM)
        {

            _ap = SYM;
        }
        // GET: SYM
        public ActionResult Index()
        {
            SYMViewModel SYM = new SYMViewModel();
            IList<ISYM> list = _ap.getDataList();

            var query = (from item in list
                         select new SYMViewModel
                         {
            編號 = item.id,
            委員姓名 = item.ass_name,
            性別 = item.gender,
            機關名稱 = item.unitname,
            職稱 = item.jobtitle,
            在職情形 = item.servicestate,
            連絡電話 = item.phone
        }).ToList();

            return View(query);
        }

        [HttpPost]
        public ActionResult Index(string search)
        {
           IList<ISYM> list = _ap.getDataList();


            var query = (from item in list
                         select new SYMViewModel
                         {
                             編號 = item.id,
                             委員姓名 = item.ass_name,
                             性別 = item.gender,
                             機關名稱 = item.unitname,
                             職稱 = item.jobtitle,
                             在職情形 = item.servicestate,
                             連絡電話 = item.phone
                         });

            query = query.Where(a => a.委員姓名.Contains(search)).ToList();
            return View(query);
        }


        public ActionResult Details(int id)
        {

            var IAP = _ap.getDataList();
            SYMViewModel APVM = new SYMViewModel();
            APVM.編號 = _ap.id;
            APVM.委員姓名 = _ap.ass_name;
            APVM.機關名稱 = _ap.unitname;

            APVM.性別 = _ap.gender;
            APVM.職稱 = _ap.jobtitle;
            APVM.在職情形 = _ap.servicestate;
            APVM.連絡電話 = _ap.phone;
            return View(APVM);
        }

        private void checkNull(SYM item)
        {
            if (string.IsNullOrEmpty(item.ass_name)) this.ModelState.AddModelError("", "請輸入委員姓名");
            if (string.IsNullOrEmpty(item.phone) && string.IsNullOrEmpty(item.tel)) this.ModelState.AddModelError("", "請輸入手機或市話");
            if (!string.IsNullOrEmpty(item.phone)) { if (item.phone.Length > 50) this.ModelState.AddModelError("", "手機輸入文字過長,請小於50個字"); }
            if (!string.IsNullOrEmpty(item.tel)) { if (item.tel.Length > 50) this.ModelState.AddModelError("", "市話輸入文字過長,請小於50個字"); }
        }

        public ActionResult returnIndex()
        {
            return RedirectToAction("Index");
        }

        public ActionResult Create()
        {
            return View();
        }
        [HttpPost]

        public ActionResult Create([Bind(Include = "編號,委員姓名,機關名稱,性別,職稱,在職情形,連絡電話")] SYMViewModel apvm)
        {
            _ap.id = apvm.編號;
            _ap.ass_name = apvm.委員姓名;
            _ap.unitname = apvm.機關名稱;
            _ap.gender = apvm.性別;
            _ap.jobtitle = apvm.職稱;
            _ap.servicestate = apvm.在職情形;
            _ap.phone = apvm.連絡電話;
            _ap.add();
            return RedirectToAction("Index");
        }
...

How to fix it?Thank you. 如何解决?谢谢。

The problem is fixed. 该问题已解决。 Here is Answer below: 这是下面的答案:

   public class SYMController : Controller
{
    ISYM _ap;
    IttaessData _ad;
    public SYMController()
    {
        _ap = new LISYM();
        _ad = new LIttaessData();
    }
    public int pageSize = 15;
    public ActionResult Index(int? page, string name)
    {
        IList<ISYM> list = _ap.getDataList();
        var query = (from item in list
                     select new SYMViewModel
                     {
                         id = item.id,
                         tta_name = item.tta_name,
                         gender = item.gender,
                         unitname = item.unitname,
                         jobtitle = item.jobtitle,
                         servicestate = item.servicestate,
                         phone = item.phone,
                         enable=item.enable
                     }).ToList();
        foreach (var item in query)
        {
            item.tta_name = item.tta_name == null ? "" : item.tta_name;
        }
        if (!string.IsNullOrEmpty(name))
        {
            query = query.Where(a => a.tta_name.Contains(name)).ToList();
        }
        query = query.Where(a => a.enable==true).ToList();
        var result = query
            .OrderByDescending(x => x.tta_name)
            .ThenBy(x => x.tta_name).ToPagedList(page ?? 1, pageSize);
        var num = query.Count();
        ViewBag.pageSize = pageSize;
        ViewBag.page = page;
        ViewBag.num = num;
        ViewBag.count = query.Count();
        ViewBag.name = name;
        return View(result);
    }
    public ActionResult Detail(int id)
    {
        if (id == null)
        {
            return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
        }
        SYMViewModel APVM = new SYMViewModel();
        ISYM IA = _ap.getSYMId(id);
        getFile(IA.picfile, IA.id);
        IList<IttaessData> list = _ad.getDataList();
        var ttaessdata = (from AD

Thank you. 谢谢。

暂无
暂无

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

相关问题 Autofac没有使用&#39;Autofac.Core.Activators.Reflection.DefaultConstructorFinder&#39;找到的构造函数 - Autofac None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' 没有在类型上使用&#39;Autofac.Core.Activators.Reflection.DefaultConstructorFinder&#39;找到的构造函数 - None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type 没有找到带有“Autofac.Core.Activators.Reflection.DefaultConstructorFinder”的构造函数 - None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' 使用 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder 找不到构造函数 - None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder 使用'Autofac.Core.Activators.Reflection.DefaultConstructorFinder'找到的构造函数都没有 - None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' DependencyResolutionException:没有找到类型为“Autofac.Core.Activators.Reflection.DefaultConstructorFinder”的构造函数 - DependencyResolutionException: None of the constructors found with 'Autofac.Core.Activators.Reflection.DefaultConstructorFinder' on type nopCommerce 项目中的 Autofac 异常(Autofac.Core.Activators.Reflection.NoConstructorsFoundException: 'No accessible constructors were found ) - Autofac exception in nopCommerce project (Autofac.Core.Activators.Reflection.NoConstructorsFoundException: 'No accessible constructors were found ) 在 Asp.NET Core 3.1 上注入依赖项时出现 Autofac.Core.Activators.Reflection.NoConstructorsFoundException - Autofac.Core.Activators.Reflection.NoConstructorsFoundException while injecting dependencies on Asp.NET Core 3.1 Autofac - 自动注册错误:没有&#39;公共绑定标志&#39;可以找到构造函数 - Autofac - auto registration error : No constructors can be found with 'Public binding flags' 对建设者的反思 - Reflection for Constructors
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM