Quantcast
Channel: Telerik Forums RSS
Viewing all articles
Browse latest Browse all 94857

Specifying an Area when binding a menu to a model

$
0
0

How do you specify an area when binding to a model?  I'm working on an ASP.NET MVC website using Areas, and using the Kendo().Menu() helper to build the menu.  I'm using the BindTo() method to bind the menu to a model that is based on Kendo.MVC.UI.MenuItem.  How do I tell the helper which area (i.e. which route) to use, and how do I specify that a particular controller is NOT in any of the areas.  The following example code example might help to illustrate the problem I'm having:

usingSystem.Collections.Generic;
usingSystem.Web.Routing;
usingMy.Resources.Views.Shared;
usingKendo.Mvc.UI;
 
namespaceMy.Web.Configuration
{
    publicclassMyMenuItem: Kendo.Mvc.UI.MenuItem
    {
        publicintId { get; set; }
        publicIEnumerable<MyMenuItem> SubItems { get; set; }
    }
 
    publicclassMySiteMap
    {
        publicMySiteMap()
        {
            MenuItems = newList<MyMenuItem>
            {
                // There is an AccountController in an Area named 'Admin'
                 
                // Neither one of the following approaches works. I think I'm close here, but I'm missing something
                // new MyMenuItem { Text = "Log In", ControllerName="Account", ActionName="Login", RouteName = "Admin"},
                // new MyMenuItem { Text = "Log In", ControllerName="Account", ActionName="Login", RouteValues = new RouteValueDictionary(new {area = "Admin"})},
 
                // The following line works the first time you click on it, but an error occurs the second
                // time, or when you try to navigate anywhere else, because the helper appends all links
                // to the Area name, once you've navigated to said area (e.g. "Home" becomes "Admin/Home"
                // which is incorrect).
                newMyMenuItem { Text = MenuResources.MenuLogin, ControllerName="Admin/Account", ActionName="Login"},
 
                // How do I tell the Kendo().Menu() helper that the 'Home' controller, e.g., is not located
                // in the 'Admin' area?
                newMyMenuItem { Text = MenuResources.MenuAbout, ControllerName="Home", ActionName="About"},
                newMyMenuItem
                {
                    Text = MenuResources.MenuProjects, ControllerName="Projects",
                    ActionName="Index",
                    SubItems = newList<MyMenuItem>
                    {
                        newMyMenuItem{Text = MenuResources.MenuProjectX,  ControllerName="Projects", ActionName="ProjectX"},
                        newMyMenuItem{Text = MenuResources.MenuProjectY, ControllerName="Projects", ActionName="ProjectY"}
                    },
                },
                newMyMenuItem { Text = MenuResources.MenuNotesToSelf, ControllerName="Blog", ActionName="Index"}
            };
            SiteMapName = "Root"; // Never displayed
        }
 
        publicstringSiteMapName { get; set; }
        publicIEnumerable<MyMenuItem> MenuItems { get; set; }
    }
 
}

Viewing all articles
Browse latest Browse all 94857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>