How do I create action links for all actions in the site?
I want to put those action links into a menu system.
I was hoping I can do something like
foreach controller in controllers {
foreach action in controller{
stringbuilder.writeline(
"<li>"+actionlink(menu, action, controller)+"<li>"
);
}
}
Here is approach how get all actions from controller Asp.net Mvc: List all the actions on a controller with specific attribute or Accessing the list of Controllers/Actions in an ASP.NET MVC application For achieving your goal you should find all controllers in your project with
Assembly.GetExportedTypes()
and filter only sub classes ofControllerBase
and for each controller callnew ReflectedControllerDescriptor(typeof(TController)).GetCanonicalActions()
from 2nd link.Here's my take on it:
The method
GetActions
as follows:If you need a menu system checkout the MVC Sitemap Provider, it will give you absolute control on what to render depending on the roles you've defined on your membership implementation.