Hus*_*ain 0 c# asp.net-web-api
我是建筑师的新手.请解释为什么它给我以下错误:
"An error occurred when trying to create a controller of type 'HomeController'. Make sure that the controller has a parameterless public constructor.
Run Code Online (Sandbox Code Playgroud)
这里我有1个接口(IRepo)1类文件(Repo)IRepo.cs
public interface IRepo
{
IEnumerable<Employee> GetEmployee();
IQueryable<Employee> GetEmployee(int id);
}
Run Code Online (Sandbox Code Playgroud)
Repo.cs
Ctxdb _db = null;
public Repo(Ctxdb db)
{
this._db = db;
}
public IEnumerable<Employee> GetEmployee()
{
//
}
Run Code Online (Sandbox Code Playgroud)
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");
}
Run Code Online (Sandbox Code Playgroud)