The 1st route works.
e.g. api/Shelves/SpaceTypes/1
The 2nd route doesn't work. I get multiple actions error.
e.g api/Shelves/1
Q) Why?
These are my routes:
config.Routes.MapHttpRoute(
"DefaultApiWithAction",
"api/{controller}/{action}/{id}"
);
config.Routes.MapHttpRoute(
"DefaultApiWithId",
"api/{controller}/{id}",
null,
new { id = @"\d+" }
);
This is my controller:
public HttpResponseMessage Get(int id)
{
...
}
[ActionName("SpaceTypes")]
public HttpResponseMessage GetSpaceTypes(int id)
{
...
}
For MVC 4.5 this is the only thing that works
There is currently a bug about this.
In order to get your routing to work so the following work
you need to do the following.
Change your routing over to. (Note the default action..)
In your controller change the base methods over to
Now everything should work as expected..
Thanks to Kip Streithorst full this, for a full explanation
Make sure in your project's Global.asx file, that you've added
into the Application_Start function.
@Kristof is almost right. You should make your second route:
This route does not know which action to bind to :
Both of your methods are a valid candidate.
I'm not 100% clear what your setup is but in normal REST every resource has a controller, it seems like you have 1 controller with 2 resources.
To make it work in this setup you could force your second route to the get action like this :
I had a similar issue and discovered i wasn't calling MapHttpAttributeRoutes method in my WebApiConfig...
hope it helps, David