1. Front-end Commit JSON string
{"id": "title": "Here is the caption", "Day": "2018-8-16", "status": 0, "arr": [{"Type": "R", "Quest": "333", "Q1": "3", "Q2": "3", "Q3 ":" 3 "},{" type ":" C "," Quest ":" 444 "," Q1 ":" 4 "," Q2 ":" 4 "," Q3 ":" 4 "},{" type ":" T "," Quest ":" 5 "}]}
$.ajax ({ "/survey/post", Method:"Post", Data:json, " Application/json ", function (data) { console.log (data.status); } })
Back-end MVC controller (version<=5), if it is WEBAPI, add the [frombody] modifier parameter
public class Surveydto {public string ID {get; set;} public string Title {get; set;} Public DateTime Day {get; set;} public string Status {get; set;} Public surveyitem[] Arr {get; set;} } public class Surveyitem {public string type {get; set;} public string Quest {get; set;} public string Q1 {get; set;} public string Q2 {get; set;} public string Q3 {get; set;} } [HttpPost] Public ActionResult Post (surveydto data) {}
JSON with an array is usually not used directly with entityframework entities. To redefine.
2. Front-end Use form submission
function (JSON) { if (json.issuccess) { } });
$.ajax ({
URL: "/survey/postform",
Method: "Post",
Data: "id=" + key + "&title=" + title + "&day=" + Date + "&status=" + STA + "&arr=" + json.stringify (this. Storagearr),
Success:function (data) {
Console.log (Data.status);
}
})
Back end uses FormCollection to accept parameters
[HttpPost] Public ActionResult Post (formcollection form) { var json = new {status = 0}; Return JSON (JSON); }
Model Binding for the front-end and back-end of MVC