2

I have created a custom Navigation controller for breadcrumb under the Navigations folder of my project module (DXA 1.7 .NET). However, I am getting the below error on every page:

The controller for path "requested page url" was not found or does not implement IController

Here is the Compoent Template: enter image description here

Here is the Project Structure:

enter image description here

I have added the entry in project Area Registration:

RegisterViewModel("Breadcrumb", typeof(NavigationLinks), "Navigations");

Also here is the code for the NavigationsController:

public class NavigationsController : NavigationController
{
    public override ActionResult Navigation(EntityModel entity, string navType, int containerSize = 0)
    {
        if (navType.Trim().ToLower() == "topmenu")
        {
            SitemapItem model = SiteConfiguration.NavigationProvider.GetNavigationModel(WebRequestContext.Localization);
            EntityModel sourceModel = (EnrichModel(entity) as EntityModel) ?? entity;
            model.XpmMetadata = sourceModel.XpmMetadata;
            model.XpmPropertyMetadata = sourceModel.XpmPropertyMetadata;
            return View(sourceModel.MvcData.ViewName, model);
        }
        else
        {
            return base.Navigation(entity, navType, containerSize);
        }
    }
}

Here is the entry in Global.asax

// Navigation JSON
routes.MapRoute(
    "Core_Navigation",
    "navigation.json",
    new { controller = "Navigations", action = "SiteMapJson" }
).DataTokens.Add("area", "XXX");
routes.MapRoute(
    "Core_Navigation_loc",
     "{localization}/navigation.json",
     new { controller = "Navigations", action = "SiteMapJson" }
).DataTokens.Add("area", "XXX");

Please suggest If I have missed anything here? I am not sure why it is showing the Page URL in the error message? I have looked into a similar issue (DXA Custom Controller Issue (Routing)) posted on stack previously, but its scenario is different.

Here is the full StackTrace :

` StackTrace " at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerWrapper.Wrap[TResult](Func1 func)\r\n at System.Web.Mvc.HttpHandlerUtil.ServerExecuteHttpHandlerAsyncWrapper.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)\r\n at System.Web.HttpServerUtility.ExecuteInternal(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage, VirtualPath path, VirtualPath filePath, String physPath, Exception error, String queryStringOverride)\r\n at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm, Boolean setPreviousPage)\r\n at System.Web.HttpServerUtility.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)\r\n at System.Web.HttpServerUtilityWrapper.Execute(IHttpHandler handler, TextWriter writer, Boolean preserveForm)\r\n at System.Web.Mvc.Html.ChildActionExtensions.ActionHelper(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues, TextWriter textWriter)\r\n at System.Web.Mvc.Html.ChildActionExtensions.Action(HtmlHelper htmlHelper, String actionName, String controllerName, RouteValueDictionary routeValues)\r\n at Sdl.Web.Mvc.Html.HtmlHelperExtensions.DxaEntity(HtmlHelper htmlHelper, EntityModel entity, Int32 containerSize)\r\n at Sdl.Web.Mvc.Html.HtmlHelperExtensions.DxaEntities(HtmlHelper htmlHelper, Int32 containerSize)\r\n at ASP._Page_Areas_XXX_Views_Region_BreadcrumbContainer_cshtml.Execute() in c:\D\Projects\XXX\WebSite-SouceCode\XXX\Areas\XXX\Views\Region\BreadcrumbContainer.cshtml:line 2\r\n at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()\r\n at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()\r\n at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)\r\n
at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)\r\n at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)\r\n at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)\r\n at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)\r\n at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)\r\n
at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)" string

`

6
  • What is the full stack trace of the error? Nov 14, 2017 at 15:20
  • Why do you change the routes for navigation.json in Global.asax ? It seems your custom navigation controller doesn't override the SiteMapJson action? Nov 14, 2017 at 15:22
  • @RickPannekoek, I have added the StackTrace. Nov 14, 2017 at 16:44
  • Try putting your Controller in the same namespace as your AreaRegistration class. Nov 14, 2017 at 20:49
  • Oh. I will try that and confirm. Nov 15, 2017 at 11:34

1 Answer 1

2

ASP.NET MVC use a bit of magic to find Controller classes. By default, it assumes that Controllers are in the same namespace as the AreaRegistration class (or a sub namespace).

Given your project structure, it seems this is not the case and hence the Controller cannot be found. You could change the namespace of your Controller or AreaRegistration class.

Alternatively, you can add namespaces to the AreaRegistrationContext. See, for example: https://github.com/sdl/dxa-web-application-dotnet/blob/release/1.7/Sdl.Web.Mvc/Configuration/BaseAreaRegistration.cs

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.