mccalltd / AttributeRouting

Define your routes using attributes on actions in ASP.NET MVC and Web API.
http://mccalltd.github.io/AttributeRouting/
MIT License
416 stars 89 forks source link

Get() and Get(string id) #220

Closed smolesen closed 11 years ago

smolesen commented 11 years ago

Hi

Is it possible to have the following two actionmethods: [RoutePrefix("test")] public class MyController : ApiController {

[GET("")] public HttpResponseMessage Get() { ... }

[GET("")] public HttpResponseMessage Get(string id) { ... }

and hit the first one with:

~/test

and the second with:

~/test?id=123

I've tried using [GET("id={id}")] for the second one, but I always seem to hit the first one...

TIA

/Søren

mccalltd commented 11 years ago

The first route is the one that will match, as route precedence is determined by the order of the actions in a controller. Also, querystring params specified in the URL will have no effect in web api. If you want to have these work, do this:

// Define route prefix above....

[GET("")] // accessible at ~/test
public Whatever Get()

[GET("{id}")] // accessible at ~/test/123
public Whatever Get(string id)