views:

268

answers:

1

I've made an Area project for my ASP.NET MVC application called 'Admin'.

This will contain all the logic for the Administration section of the site, where the users can add/remove pages, etc.

There's a menu at the top, of things the user can manage. (E.g. 'Content', 'Users', etc)

For each of these, I'm making a controller ('ContentController', 'UsersController', etc)

I'm wondering how to setup the navigation, as there seem to be varying approaches.

One approach is to use MvcSiteMap, which involves creating a '.sitemap' file and decorating actions on my controllers with an 'MvcSiteMapNode' attribute.

The problem with the above is that it's complicated to implement (especially in an Area project, because of the way Areas work in ASP.NET MVC). It also seems like overkill.

I've come up with a different way, which is to decorate each controller with my own attribute. Then I have a helper method that renders my navigation by using reflection to loop through every controller, pick out the ones that have that attribute, and then add them to the navigation menu.

What are your thoughts on the above method? Can you think of an even simpler way of doing this?

+1  A: 

So I've done it my way - an attribute on each controller, then a static method that reads all the attributes on application start (using reflection) and keeps them in memory.

So far this has worked perfectly, and I haven't needed any of the advanced features of MvcSiteMap.

jonathanconway
I'm looking for *exactly* this (navigation based on controller/action attributes) -- any chance you can post your source, nomatter how messy?
Portman
The latest version of MvcSiteMap seems to support this, using the [MvcSiteMapNode] attribute. http://mvcsitemap.codeplex.com/ - go here and search for MvcSiteMapNode.
jonathanconway