This is my DefaultApi configuration:
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{id}/{action}",
defaults: new { action = "DefaultAction", id = RouteParameter.Optional }
);
[ActionName("DefaultAction")]
public HttpResponseMessage Get(string id)
[ActionName("DefaultAction")]
public HttpResponseMessage Post(MyClass obj)
How come GET
works but using POST
I get a 404 Not Found
error?
Any ideas or suggestions?
Edit:
Client JavaScript:
$.ajax({
type: "POST",
url: "@Url.Content("~/api/controllername")",
data: args,
200: function (data) {
......
}
});
I had a similar problem and the solution was to add [FromBody]
to the method's paramter like this:
[HttpPost]
public void PostIncreaseViewCounter([FromBody]int id)
{
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With