当我尝试运行MVC时,出现以下错误:
在类型为“ A105004P.Controllers.AssessPersonController”的“ Autofac.Core.Activators.Reflection.DefaultConstructorFinder”中找不到任何构造函数,都可以使用可用的服务和参数进行调用: 无法解析构造函数“ Void .ctor(Library.Interface.IAssessPerson)”的参数“ Library.Interface.IAssessPerson AssessPerson”。
以下是相关文件:
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
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");
}
...
如何解决?谢谢。
答案 0 :(得分:0)
问题已解决。这是下面的答案:
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
谢谢。