問題描述
Успадкоўванне кантролера ASP.NET MVC 4 (ASP.NET MVC 4 controller inheritance)
I have the following setup: BaseController1 inherits System.Web.Mvc.Controller. This controller is compiled into a separate dll that is referenced from my project. BaseController2 inherits BaseController1 in my project. MyController inherits BaseController2. When I run application with this setup, I get 404 error. But if BaseController2 inherits directly System.Web.Mvc.Controller, and I run application with this setup, everything works as expected. I have default constructor for all inherited controllers with : base() called. The BaseController1 within assembly is compiled using references to asp.net mvc 3, and my project relies completely on asp.net mvc 4. Can this be the problem? Or I am doing something wrong. Thanks in advance!
‑‑‑‑‑
參考解法
方法 1:
You're doing nothing wrong, but you will have to make MVC look in the specific assembly/namespace:
ControllerBuilder.Current.DefaultNamespaces.Add(
"ExternalAssembly.Controllers");
This has already been answered in this question: asp.net mvc put controllers into a separate project