Can someone help me fill in the blanks with my GET methods for webapi. I want to pass in no parameters and get all results. Pass in an int and get a single result and pass in a named parameter to filter by a typeId / zoneId or both but am struggling to get this to work.
TimeController : ApiController
// Time/
//Time/1
//Time/typeId=1
//Time/zoneId=1
Time/typeId=1&zoneId=1
The closest I got was with
Global
RouteTable.Routes.MapHttpRoute(name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = System.Web.Http.RouteParameter.Optional}
);
RouteTable.Routes.MapHttpRoute(name: "TemplateTimeApi",
routeTemplate: "api/{controller}/{typeId}/{zoneId}",
defaults: new {typeId = RouteParameter.Optional, zoneId = RouteParameter.Optional }
);
Controller
List<TimeView> Get(int typeId, int? zoneId = null)
TimeView Get(int id)
but I get a 404 on no parameters.
I can change one of the parameters to a string if the issue is with two integers, however, I would prefer to understand the issue and get it to work.