I am trying to create an area in a separate assembly. My route appears correct, according to RouteDebugger, but I am getting a “The controller for path {0} was not found or does not implement IController.” error.
I verified that the controller is registered in my container, but under a different namespace which I am specifying in my route.
Route registration:
routes.MapRoute(
"EventCalendar",
"EventCalendar/{action}/{id}",
new { controller = "EventCalendar", action = "Index", id = UrlParameter.Optional },
new[] { "MyAssembly.MyName.Controllers", " MyAssembly.MyName" }
);
Controller:
namespace MyAssembly.MyName.Controllers
{
public class EventCalendarController : Controller
{
public PartialViewResult Index()
{
return new PartialViewResult
{
ViewName = "~/Views/EventCalendar/Index.cshtml",
ViewData = new ViewDataDictionary<object>(this.ViewData.Model)
};
}
}
}
I am specifying both the namespace of the controller and the parent namespace in the route. Examples I have looked at are not clear as to which one is required. OrchardCMS uses the parent namespace.
Am I registering the route correctly?
As long as the controller is in my container, and the namespace matches, it should resolve and be invoked right? The controllers in the main assembly work fine.
You may want to use Dependency Injection for doing that. I’m working on a project with a similar approach (some Controllers in separated assemblies) and we’re using Unity to inject the controllers to the MVC project. Maybe this URL could be helpful
Also please ensure that the corresponding dll is on the bin folder of your MVC project, so the type can be resolved