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 book Pro ASP.NET MVC 4 and most of the online examples I've found give examples like:
public class ServicesController : ApiController
{
public string[] MethodFruit()
{
return new string[] { "Apple", "Orange", "Banana" };
}
accessed via the URL:
http://mysite/services/methodfruit
But that never works - the resource isn't found. The only approach I can get working is to have the controller contain a different method for each HTTP verb, then:
http://mysite/api/services
Which calls the GET method.
I checked the Apress website but they don't seem to have any forums and the current source code is in VS 2012 which I'm not using. I examined the source files and they seem to think the former approach should work. Is the former approach no longer supported?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…