Controller/Action

Topics: General
Feb 14, 2012 at 9:34 PM

Coming from event driven programming background, I am struggling to figure out which part of the code is getting executed when certain UI elements are being clicked. Is there any way in orchard to determine what controller and action is getting fired up.  I am curious if there is any technique applied to determine this.

 

Thanks

Coordinator
Feb 14, 2012 at 11:09 PM

It should be pretty plain by looking at the link url or form action, then comparing with routes.

Feb 15, 2012 at 2:19 PM

Pardon my ignorence, where are all the routes defined ? What I know

1) It should be defined in the global.asax

2) It should be define in Routes file in the root folder.

Where in Orchard project ?

 

Thanks

 

 

Feb 15, 2012 at 2:29 PM

Typically you create Routes.cs in the root of your module, though it doesn't matter where you place it because Orchard will pick up your routes as long as the class implements the IRouteProvider interface. 

Here's an example, the Routes.cs from Orchard.Blogs

Feb 15, 2012 at 3:01 PM

If there is no Routes.cs defined for the modules what does that mean ?

Thanks

Feb 15, 2012 at 5:05 PM

It means you haven't created it yet. 

Coordinator
Feb 15, 2012 at 5:36 PM

In MVC all the routes end up in the RouteCollection. Same is for Orchard because it uses MVC. But in Orchard we can't afford to declare them in the Global.asax because we need extensibility. So what is actually done is that we provide an interface IRouteProvider that you can implement to declare your routes in a module. then Orchard loads all those implementations for the active modules, in each active tenant, and at startup populates the RouteCollection with the results of those classes.