I want to have two different GET action to query the data by, name and id,
I have these routes:
config.Routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "ActionApiByName",
routeTemplate: "api/{controller}/{action}/{name}",
defaults: new { name = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
and these actions in the controller:
[HttpGet]
public CompanyModel CompanyId(Guid id)
{
//Do something
}
[HttpGet]
public CompanyModel CompanyName(string name)
{
//Do something
}
while a call like this: http://localhost:51119/api/companies/CompanyId/3cd97fbc-524e-47cd-836c-d709e94c5e1e
works and gets to the 'CompanyId' method,
a similar call to http://localhost:51119/api/companies/CompanyName/something
gets me to 404 not found
but this:
'http://localhost:51119/api/companies/CompanyName/?name=something
' works fine
Can anyone explain this behaviour and what am I doing wrong?