0
我是新来的构造函数请解释为什么它给我下面的错误:“出错确保控制器具有一个无参数的公共构造
"An error occurred when trying to create a controller of type 'HomeController'. Make sure that the controller has a parameterless public constructor.
这里我有1接口(IRepo)1类文件(回购) IRepo.cs
public interface IRepo
{
IEnumerable<Employee> GetEmployee();
IQueryable<Employee> GetEmployee(int id);
}
Repo.cs
Ctxdb _db = null;
public Repo(Ctxdb db)
{
this._db = db;
}
public IEnumerable<Employee> GetEmployee()
{
//
}
个
HomeController.cs
IRepo _ObjRepo = null;
public HomeController(Repo ObjRepo)
{
_ObjRepo = ObjRepo;
}
[Route("GetEmp")]
[HttpGet]
public IHttpActionResult GetDat()
{
var x = _ObjRepo.GetEmployee();
if (x != null)
return Content(HttpStatusCode.OK, x);
else
return Content(HttpStatusCode.BadRequest,"Not Implemented");
}
只是在你的控制器中有一个无参数的构造函数。 –
但是,即时通讯管理它可能你plz给我任何提示 – Hussain
这很清楚:你需要创建一个没有参数的公共构造函数...例如:'公共HomeController()'还有很多问题的答案,谈话关于这个问题。请参考这些帖子 –