我试图定义ASP.NET MVC项目基本控制器 -BaseController不包含一个构造函数参数0
public abstract class BaseController:Controller
{
protected readonly ExpressDbContext DbContext;
string _baseUrl;
public BaseController(ExpressDbContext context)
{
_baseUrl = ConfigurationManager.AppSettings["BaseUrl"].ToString();
DbContext = context;
}
protected new ViewResult View()
{
this.ViewBag.BaseUrl = _baseUrl;
return base.View();
}
}
然后从其他控制器 -
public class HomeController : BaseController
{
public ActionResult Index()
{
return View();
}
}
我继承它看到了一些例子来声明这样的基础控制器。但是,这一次我得到exception-
BaseController does not contain a constructor that takes 0 arguments
我也Ninject绑定的DbContext -
kernel.Bind<ExpressMvc.DB.ExpressDbContext>().ToSelf().InRequestScope();
任何事情,我错过了或不认识的?
在你的'BaseController',加入这行代码'公共BaseController(){ }'和that't吧:) – Hackerman
检查出来可能是你缺少ninject.web.mvc包。 – Rajput