Question

We have an MVC5 application using Sitemap Provider 4.5.2 Overall it's working fine in 99% of cases..

Where it doesn't work is where we have a custom route defined in AreaRegistration.cs if we comment out the custom route, the breadcrumb works.. but we need the route in place for some custom parameters.

Below is the route as defined in our AreaRegsitration.cs

//ATS/Vacancy/Edit/33
context.MapRoute(
    "ATS_Vacancy",
    "ATS/Vacancy/{action}/{VacancyID}",
    new { Controller = "Vacancy", VacancyID = UrlParameter.Optional }
);

The site map node looks like below, and it's the "Create Vacancy" Node that doesn't render on the page. Everywhere else in the application works fine, I've removed the bulk of the nodes to make it more readable.

<mvcSiteMapNode title="Home" controller="Home" area="ATS" action="Index" >
<mvcSiteMapNode title="Vacancy Manager" controller="Vacancies" area="ATS" action="Index" >
<!--Busted Node-->
<mvcSiteMapNode title="Create Vacancy"  controller="Vacancy" area="ATS" action="Create" preservedRouteParameters="VacancyID" cacheResolvedUrl="false" route="ATS_Vacancy" ></mvcSiteMapNode></mvcSiteMapNode>

We have been scratching our heads for some time now, and tried many different things found on the web but to no avail.. The routing engine is working fine & the page is resolved everytime. The sitemap also resolves to the correct node when a route is specified, but it seems unable to render it out..

Any suggestions would be most welcome. Thank you for your thoughts....

Was it helpful?

Solution

You must include at least 1 namespace in your routes when using areas with MvcSiteMapProvider for it to determine the area name.

//ATS/Vacancy/Edit/33
context.MapRoute(
    "ATS_Vacancy",
    "ATS/Vacancy/{action}/{VacancyID}",
    new { Controller = "Vacancy", VacancyID = UrlParameter.Optional },
    new string[] { "MyNamespace.Areas.ATS.Controllers" }
);

See this answer for more information.

OTHER TIPS

Your route looks similar to a default route.

If possible, change your controller action methods to accept id rather than VacancyID and remove your custom route and see if that works.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top