AdminMenu.cs question

Topics: Writing modules
Jun 10, 2011 at 7:23 PM

I've written a few modules now, and I've followed the naming convention that it seems orchard out of the box stuff follows:


So when I'm adding an admin menu item, I use the following code:

public void GetNavigation(NavigationBuilder builder) {
                .Add(T("ModuleName"), "11",
                    menu => menu.Action("Index", "Admin", new { area = "CompanyName.ModuleName" }).Permission(StandardPermissions.SiteOwner)
                        .Add(T("Users"), "1.0", item => item.Action("Index", "Admin", new { area = "CompanyName.ModuleName" })

This works, but the URL that gets generated for this menu item is:

I looked in some of the other modules and they follow the same naming method (as far as I can tell) but the generated URL is something like:

What am I missing? How do I make the admin url a little more friendly?

Jun 10, 2011 at 8:52 PM

Routes :)

The URL will be whatever the route is to that action you specified. So specify a nicer route and it will jsut pick it up. It can be if you want.

Jun 10, 2011 at 8:59 PM

In the routes.cs file? As far as I could see, the Orchard.Users module doesn't have a routes.cs file, and the AdminMenu.cs specifies Orchard.Users...that's why I was getting confused...

Jun 10, 2011 at 9:34 PM

Ah, yes, some default routes are being generated from StandardExtensionsRouteProvider in Orchard.Framework. These are based on data that ultimately comes from the manifest of the extension. There is a Path property in the extension descriptor that's being used for that, that gets populated by the extension loader if I'm not mistaken.

But I don't think you need to dig that deep, and defining a friendlier route in Routes.cs should do the trick as far as you're concerned.

Jun 10, 2011 at 9:36 PM

That makes sense. I knew it had to be coming from somewhere...

Jun 13, 2011 at 7:21 PM

So I added the route in the routes.cs file, and the menu item magically picked up the change and directed me to the correct,newly routed url.  Pretty cool...I had been searching around for how to make adminmenu.cs do this but accidentally found out that it did it for me on the fly.

Jun 13, 2011 at 10:33 PM

Yup, that's MVC - from an area/controller/action it can reverse-build the actual URL based on the route table.