asp.net mvc - Scan for all actions in the site -


how create action links actions in site?
want put action links menu system.

i hoping can

foreach controller in controllers {     foreach action in controller{         stringbuilder.writeline(             "<li>"+actionlink(menu, action, controller)+"<li>"         );     } } 

here's take on it:

var controllers = assembly.getcallingassembly().gettypes().where(type => type.issubclassof(typeof(controller))).tolist(); var controllist = controllers.select(controller =>                                      new                                      {                                          actions = getactions(controller),                                          name = controller.name,                                      }).tolist(); 

the method getactions follows:

public static list<string> getactions(type controller) {     // list of links     var items = new list<string>();      // descriptor of controller     var controllerdesc = new reflectedcontrollerdescriptor(controller);      // @ each action in controller     foreach (var action in controllerdesc.getcanonicalactions())     {         // attributes (filters) on action         var attributes = action.getcustomattributes(false);          // @ each attribute         var validaction =             attributes.all(filter => !(filter httppostattribute) && !(filter childactiononlyattribute));          // add action list if it's "valid"         if (validaction)            items.add(action.actionname);     }     return items; } 

if need menu system checkout mvc sitemap provider, give absolute control on render depending on roles you've defined on membership implementation.


Comments

Popular posts from this blog

ios - iPhone/iPad different view orientations in different views , and apple approval process -

java Extracting Zip file -

C# WinForm - loading screen -