This is a migrated thread and some comments may be shown as answers.
Strange Behaviour with Menus and Areas
0 Answers 38 Views
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Andy
Top achievements
Rank 1
Andy asked on 17 Aug 2010, 03:14 PM
Hi,

I'm getting a conflicting effect when using menus on a project that has multiple areas.  The app is structured with the following site maps:
web.sitemap:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
    <siteMapNode title="Root">
        <siteMapNode title="Home"           area=""                 controller="Home" action="Index" />
        <siteMapNode title="Area 1"         area="Area1"            controller="Home" action="Index" />
        <siteMapNode title="Area 2"         area="Area2"            controller="Home" action="Index" />
        <siteMapNode title="Admin"          area="Administration"   controller="Home" action="Index" />
        <siteMapNode title="Help"           url="~/Help/Index.aspx" />
    </siteMapNode>
</siteMap>
admin.sitemap:
<?xml version="1.0" encoding="utf-8" ?>
<siteMap>
    <siteMapNode title="Root">
        <siteMapNode title="Admin"       area="Administration" controller="Home"     action="Index" />
        <siteMapNode title="Users"      area="Administration" controller="User" action="Index" />
    </siteMapNode>
</siteMap>

The main menu is defined in the site.master and there's a submenu in the admin.master which inherits the site.master.   I've decorated /Areas/Administration/Controllers/HomeController with the [Authorize] attribute.

On the main menu, the Admin link is displayed, but the submenu link isn't even though they both point to the same controller with the same action in the same area.   I think the problem is down to areas - the main menu has effectively got a different area albiet equal to string.empty and the IsAuthorized check doesn't take the area into account.

I've tried manually creating the menus without .Bind() and the effect is the same.   I'm using the following as a get around for now:
Html.Telerik().Menu()
        .Name("main-menu")
        .BindTo("MainSiteMap")
        .ItemAction(action=>
            {
                action.Enabled = Minerva.Services.PermissionsService.IsVisible((string)action.RouteValues["Area"], action.ControllerName, action.ActionName);
            })
        .Render();

Its a bit messy and I feel its in violation of DRY.

Andy
Tags
Menu
Asked by
Andy
Top achievements
Rank 1
Share this question
or