I've used the selected answer from here: Routing based on query string parameter name to build my routes but they don't work as expected:
my route:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}",
defaults: new { controller = "Products" }
);
my actions:
public string GetProductById(int id) {}
public string GetProductByIsbn(string isbn) {}
I am trying to call these via:
localhost:60819/api/products/id=33 //doesn't work
localhost:60819/api/products/33 //does work
and
http://localhost:60819/api/products/isbn=9781408845240 //doesn't work
http://localhost:60819/api/products/testString //test with a definite string - doesn't work - still tries to use GetProductById(int id)
the error is the same for both that don't work:
<Error><Message>The request is invalid.</Message>
<MessageDetail>
The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.String GetProductById(Int32)' in 'BB_WebApi.Controllers.ProductsController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
</MessageDetail>
</Error>
Seems to think the id isn't being passed in...?
I've read up all the msdn docs but I seem to be missing something somewhere. Can anyone see where I'm going wrong?