According to the normal wording, there are always 404 errors, studied for a long time, found here the solution: Http://buxuxiao.com/article/using-jquery-to-post-frombody-parameters-to-web-api
Now summarize,
In case of a single parameter:
1, the background parameters of the correct wording as follows:
[Route ("services/{controller}/{action}")][httppost][httpget] Public string Uploadtransportnetworkalarmchat ([frombody]string obj) {
...}
You must precede the parameter list with the [Formbody] label.
2, the parameters of the foreground, still added in Key-value mode, but the key name must be set to null:
$.ajax ({ "POST", ".. /services/chattest/uploadtransportnetworkalarmchat ", data: {" ":" HelloWorld "}, ' JSON ' ,})
Multiple parameters in the case,
1, the background needs to define the entity class, the parameter list does not add the [Frombody] label, as follows:
Public class Tempobj { publicstringgetset;} Public string Get Set ; } }
Receive method:
[Route ("services/{controller}/{action}")] [HttpPost] [HttpGet] Public string uploadtransportnetworkalarmchat (tempobj obj) {}
2. The foreground still uses JSON
var Tempobj = {"ImgBase64": Image, "name": "HelloWorld" } $.ajax ({ "POST", "..") /services/chattest/uploadtransportnetworkalarmchat ", data:tempobj, ' JSON ', }) . Done (function (data) { alert ("Data Loaded:" + data); });