CustomRoute url

Imported from the CodePlex archive for reference purposes. Support for MvcCodeRouting has ended.

Commented on
Hi Max,

Thank you for the good work.
We dont like hard coded values in our application. So instead of using
CustomRoute("~car/information/{carId}") , Is there any other way I can represent the url?
Thank you for your help

Thanks
bindu
Commented on link
namespace MyApp.Car {

   public class InformationController : Controller {
   
      [CustomRoute("{id}")]
      public ActionResult Information([FromRoute]int id) {
         ...
      }
   }
}
...asuming the root controller is something like MyApp.HomeController.
Commented on link
As a follow on to this... How do we get routing to an ApiController at its root?

For example:

http://foo.com/entity

(which returns an unfiltered collection of entities)

You demonstrate above how to get at a unique item using:

http://foo.com/entity/123

(which returns single entity of id 123)

How do we map a root url?
Commented on link
Nevermind, I just figured it out...

Decorating the Action method with [CustomRoute("")] did the trick.

This MvcCodeRouting framework has really been a great addition when writing RESTful Api's.

Thanks again for the good work.
Commented on link
It's simpler than that, just create an action named Get. No need to use [CustomRoute].
Commented on link
Even better - thanks!