Another night, and finally figured it out.
The Webapi pit was so miserable.
Before using various methods of post, sometimes can read the structure, but no value, sometimes directly is a null, and sometimes even the method is not in the run, just to the controller to see a bit ...
The last friend said or use JSON, so went back to see, finally experiment for a long time, finally succeeded.
First, the use of
: Apicontroller
interface, rather than the normal Mvccontroller
Second, the name of the method is this:
[HttpPost] public response<string> posttest ([frombody]jobject value)
Finally, get the data:
Jtoken JTK = value. GetValue ("Data"); list<model> list = jtk. Toobject<list<model>> ();
So you can get a list<model>.
Of course, to reference a DLL:
Using Newtonsoft.Json.Linq;
At the same time, the client has to do some setup:
Such as:
When sending JSON, add:
"Content-type", "Application/json"
Indicates that it is a JSON
Also, be aware of the relationship between the key and the content of data:
Data corresponding to the content is not double quotation marks.
It should be almost the same.
Well, you can have breakfast.
WEBAPI when submitting JSON with post, get no value or do not go to the corresponding method problem