I read a ton of similar messages that describe the same error message, but they don't seem to match what I'm experiencing.
I recently started using the web API and ripped off all my MVC methods, from where I returned JSON, etc., so MVC will just display html and I will call the model via ajax from my webapi controllers.
Here's the weird thing, I can get and post from my Home apiController (so that I can login / register, etc.), but I can only get from the API controller in the area that I created. I get 405 (the method is not valid), although it is decorated and called in the same way as the other controller. I assume that routing is in order, otherwise it will not return my initial income?
Routing
public static void Register(HttpConfiguration config) { config.Routes.MapHttpRoute( name: "DefaultAreaApi", routeTemplate: "api/{area}/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); config.Routes.MapHttpRoute( name: "DefaultApi", routeTemplate: "api/{controller}/{action}/{id}", defaults: new { id = RouteParameter.Optional } ); }
controller
// Returns Model [HttpGet] public HttpResponseMessage SelectAgent() // The requested resource does not support http method 'POST'. [HttpPost] public HttpResponseMessage SelectAgent(Guid id)
JQuery
// Works fine $.ajax({ type: 'POST', url: '/api/Home/Login', headers: options.headers, contentType: "application/json; charset=utf-8", dataType: 'JSON', data: ko.toJSON(self.serverModel), success: function (response) { // Works fine $.getJSON("/api/Account/Users/SelectAgent", function (model) { .... // 405 $.ajax({ type: 'POST', url: '/api/Account/Users/SelectAgent', headers: options.headers, contentType: "application/json; charset=utf-8", dataType: 'JSON', data: "{'id':'" + selectModel.agentId() + "'}", success: function (response) {....
the transmitted data seems fine (or at least for the MVC controller he worked with).
I have not modified the Home API Controller at all, I donβt understand how I can publish this, and not my other controller. Argh.
Any pointers in the right direction would be awesome.