in the WebApiConfig.cs file of my Web API project I have replaced the default routing mapping to this one:
config.Routes.MapHttpRoute(
name: "ContActId",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
as I want controller and action combinations instead of a lot of GETs and POSTs.
The problem is this. I have a controller CityController with below 2 actions.
[HttpGet]
public HttpResponseMessage GenderCount()
{
//Validate session and fetch gender related data of the city
return Request.CreateResponse(HttpStatusCode.OK, genderData);
}
[HttpGet]
public HttpResponseMessage GenderCount(string cityID)
{
//Validate session and fetch gender related data of the city
return Request.CreateResponse(HttpStatusCode.OK, genderData);
}
The {HostName}/api/City/GenderCount?cityID=4 API call works but when I try to issue the same API call in the {HostName}/api/City/GenderCount/4 format, it goes to the without-parameter 'GenderCount()' action.
idroute parameter. change action parameter fromstring cityIDtostring idor do the reverse and update the route itself.