Routes not finding controller

Topics: Writing modules
Dec 16, 2011 at 11:31 AM

Hello, I'm trying to emulate the FeaturedItemSlider in inserting a menu item on the admin screen that is used to manage content items. When I go to the route address (or click on the menu item pointing to it) an exception is thrown that it can't find the controller type.

Routes.cs

namespace weVi.EmbeddedContent
{
    public class Routes : IRouteProvider
    {
        public IEnumerable<RouteDescriptor> GetRoutes()
        {
            const string areaName = "EmbeddedContent";
            var emptyConstraints = new RouteValueDictionary();
            var sliderRouteValueDictionary = new RouteValueDictionary { { "area", areaName } };
            var mvcRouteHandler = new MvcRouteHandler();

            return new[] {
                new RouteDescriptor {
                    Route = new Route(
                        "Admin/EmbeddedContent/Sources",
                        new RouteValueDictionary {
                            {"area", areaName},
                            {"controller", "Admin"},
                            {"action", "NewCreate"}
                        },
                        emptyConstraints, sliderRouteValueDictionary, mvcRouteHandler)
                }
            };
        }

        public void GetRoutes(ICollection<RouteDescriptor> routes)
        {
            foreach (var routeDescriptor in GetRoutes())
                routes.Add(routeDescriptor);
        }
    }
}

Controllers/AdminController.cs

namespace weVi.EmbeddedContent.Controllers
{
     [ValidateInput(false), Admin]
    public class AdminController : Controller
    {

        private readonly IContentManager _contentManager;

        public AdminController(IContentManager contentManager, IShapeFactory shapeFactory)
        {
            _contentManager = contentManager;
            Shape = shapeFactory;
        }

        dynamic Shape { get; set; }

        public ActionResult NewCreate()
        {
           //stuff
        }
    }
}

 

The exception is: The controller for path '/Admin/EmbeddedContent/Sources' was not found or does not implement IController.

 

Does anyone have any ideas? Thanks.

Coordinator
Dec 16, 2011 at 6:28 PM

Might be the area name.

Dec 16, 2011 at 8:05 PM

Thanks, there were two issues. The area name needs the full scoping of the namespace "weVi.EmbeddedContent" and also the namespace must match the assembly name. I had changed the namespace and not encountered any issues until now, but there you go.