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
Yep... generally you have to follow the default naming convention expected by ASP.NET WEB API.
Check this official doc:
Routing in ASP.NET Web API
If you do not want to follow the convention, you can try the Routing by Action Name section described in the above linked doc.
Routing by Action Name
With the default routing template, Web API uses the HTTP method to select the action. However, you can also create a route where the action name is included in the URI:
routes.MapHttpRoute(
name: "ActionApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional } );
In your case, you'd have to do this:
[HttpGet]
public string[] MethodFruit()
{
return new string[] { "Apple", "Orange", "Banana" };
}