I need a controller to return JSON to be consumed by JavaScript so I inherited from the ApiController class but it isn\'t behaving as I expected. The Apress bo
Adding additional information on above answer. Adding RoutePrefix would fix the issue sometimes. Hope it helps
Controller
[RoutePrefix("api/Services")]
public class ServicesController : ApiController
{
[System.Web.Http.AcceptVerbs("GET", "POST")]
[System.Web.Http.HttpGet]
[Route("MethodFruit")]
public string[] MethodFruit()
{
return new string[] { "Apple", "Orange", "Banana" };
}
}
In config
routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional } );