Greatings,
I have a problem with my asp.net mvc4 research project. I've tried to create apicontroller with multiple get actions and some of them with parameters, others - without.
my api
public class ContentController : ApiController
{
[System.Web.Http.HttpGet]
public HttpResponseMessage Categories1()
{
return Request.CreateResponse(HttpStatusCode.OK, new string[] { "Toys", "Games", "Animals", "Woob-Woob" }, Configuration.Formatters.JsonFormatter);
}
[System.Web.Http.HttpGet]
public HttpResponseMessage Categories2()
{
return Request.CreateResponse(HttpStatusCode.OK, new string[] { "Toys", "Games", "Animals", "Woob-Woob" }, Configuration.Formatters.JsonFormatter);
}
[System.Web.Http.HttpGet]
public HttpResponseMessage Categories3(int i)
{
return Request.CreateResponse(HttpStatusCode.OK, new string[] { "Toys", "Games", "Animals", "Woob-Woob" }, Configuration.Formatters.JsonFormatter);
}
[System.Web.Http.HttpGet]
public HttpResponseMessage Categories4(int i)
{
return Request.CreateResponse(HttpStatusCode.OK, new string[] { "Toys", "Games", "Animals", "Woob-Woob" }, Configuration.Formatters.JsonFormatter);
}
}
my apiConfig:
public static void Register(HttpConfiguration config)
{
config.Routes.MapHttpRoute(
name: "ApiByActionWithId",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
config.Routes.MapHttpRoute(
name: "ApiByAction",
routeTemplate: "api/{controller}/{action}"
);
config.Routes.MapHttpRoute(
name: "ApiByName",
routeTemplate: "api/{controller}/{action}/{name}",
defaults: null
);
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);
}
and the result of this
for /api/content/categories1 the result is ["Toys","Games","Animals","Woob-Woob"]
for /api/content/categories3 and /api/content/categories3/1 result - "No HTTP resource was found that matches the request URI 'http:// localhost:51200/api/content/categories3'."
I have no idea how it should be handled