I've recently hit a road block trying to use the MvcSiteMapProvider.
In my application, I have three distinct areas: Landing, Application and Administration. I currently have implemented the MvcSiteMapProvider and it works amazingly, but what I'm trying to do now - is use the Html MvcSiteMap Helper and specify a different map provider depending on the area that I'm in.
So, when I'm:
- In the "Admin" area - I want to use the provider named "AdminSiteMapProvider".
- In the "Application" area - I want to use the provider named "AppSiteMapProvider".
I've tried the following:
Shared -> _AppLayout.cshtml
@Html.Partial("_Menu")
Shared -> _Menu.cshtml
@{
if (HttpContext.Current != null && HttpContext.Current.Handler is System.Web.Mvc.MvcHandler)
{
var handler = HttpContext.Current.Handler as System.Web.Mvc.MvcHandler;
var currentArea = handler.RequestContext.RouteData.Values["area"] ?? string.Empty;
if (!string.IsNullOrEmpty(currentArea.ToString()))
{
<text>@Html.MvcSiteMap("AppSiteMapProvider").Menu()</text>
}
else if (currentArea.ToString() == "Admin")
{
<text>@Html.MvcSiteMap("AdminSiteMapProvider").Menu()</text>
}
}
}
Any suggestions? I don't want to have to copy/paste the _AppLayout.cshtml content into a new master just for one area, I'd rather it select the right provider dynamically.