I am new to WEB API and trying to set up routing for multiple GET actions.
Controller Code
// Get api/values public IEnumerable<tblUser> Get() { //whatever } // Get api/values/action [ActionName("GetByQue")] public IEnumerable<tblQue> GetQue() { //whatever } // Get api/values/action [ActionName("GetUserScore")] public IEnumerable<tblScore> GetScore(string user) { //whatever } Config
config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{id}", defaults: new { id = RouteParameter.Optional} ); config.Routes.MapHttpRoute( name: "DefaultActionApi", routeTemplate: "api/{controller}/{id}", defaults: new { action = "GetByQue" } ); config.Routes.MapHttpRoute( name: "DefaultStringApi", routeTemplate: "api/{controller}/{id}", defaults: new { action = "GetUserScore" } ); When I try with http://localhost:54118/api/remote/GetByQue URL getting this error
{ "Message": "The request is invalid.", "MessageDetail": "The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.String Get(Int32)' in 'HydTechiesApi.Controllers.HydTechiesApiController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter." } is my routing wrong? Any help would be valuable as I am not able to find a solution.