I did a very simple test on ASP.NET MVC4 WebAPI and found some interesting issue:
When a method is taking complex type, it will work, but when it takes string or int, it will throw 404, as the screen shot given: The "AddProduct" works, but "Test" and "Test1" is always not found.
How should I invoke the method correctly?
You need to decorate your string or int parameter with the [FromBody] attribute.
try this:
the website is accept the value by "[FormBody]", so you should be post by "={0}" ({0} is replaced by your string data)
see also this answer: POST a string to Web API controller in ASP.NET 4.5 and VS 2012 RC
Have you tried,
Right now it's failing becuase you've wrapped your entire json object (in the jquery ajax method) in quotes.
Try without the quotes and let me know!
Also,
When testing single variables like string username and int value take a note that WEB API will expect it exactly like that.
This guy,
Will look for a post that matches this url signature (im using HTTPIE)...
$ http POST http://yourwebsite.com/api/test1 value=1
Where the "4" is the value of the variable "value" in that Test1 method.
More about HTTPIE here: Scott Hanselman on installing HTTPIE
Hope that helps!
I searched nearly a day for this because I want my data to be a JSON, so assuming you need to post one value here it is:
INT:
STRING
CONTROLLER
using
Route
call: localhost:xx//api/product/Add