This project is read-only.

baseRoute & "~controllerName" syntax

Dec 24, 2011 at 10:14 PM
Edited Dec 24, 2011 at 10:28 PM


If I define simple base route ('{year}/{quarter}' as example) in MapCodeRoutes, MVC will stop to recognize absolute controller name syntax from master layuot :(

upd: it seems trouble in CodeRoute.cs:

               if (theController[0] == '~') {

Variable name "routeContextSegments" says that hold all segments, include baseRoute values. If we clear it, MVC can't map "some/base/route" url part  to "" and produce error.

Dec 25, 2011 at 12:01 AM

This is the intended behavior. The ~controller syntax tries to map to a controller at the root of the application. But I see your point, if someone develops a plugin with a hierarchy of controllers, and a deep controller tries to link to a top level controller using ~controller it won't work if the application developer used a baseRoute at route registration. I will think about this.

Tell me more about your scenario, do all controllers in your application use the "{year}/{quarter}" baseRoute or only some? Maybe you can use the CustomRoute attribute.

Dec 25, 2011 at 8:25 AM
Edited Dec 25, 2011 at 8:35 AM

In my application, all controllers should use "year/quarter" pair - one reason is a DDD and aggregate root, other is user (and debug) friendly urls.

So using a global ''base route" is best scenario. Now I'm use a set of routes derives from PeriodRoute class, and try to migrate on MCR. Routing loose some flexibility, but gain strict namespace-based hierarchy.

Earlier I'm think about attribute routing, and refuse it - attributes in this case smell like 'DisplayName('FistName')' in domain model class. As far as I read about this project, you agreed with me )


My fist task in migration way - render list of periods (Y2011 Q3 and so on) into master layout. Because it needed access to DB, I can't render without call to some controller. For master layout - root controller. In Html.Action I should specify absolute controller path - because layout used to render all of hierarchy levels.

Dec 25, 2011 at 4:18 PM

I thought about this and decided it's a good idea that ~controller matches routes in the same baseRoute. Added a new syntax, ~~controller, to match routes with no baseRoute. It's on the latest revision, let me know how it works for you.

Dec 25, 2011 at 5:12 PM

Thanks a lot, my base views now work! )