In the foreground submission (POST) data. In addition to the strongly typed data, there is an additional JSON data submission
My approach here is to convert the JSON object into a string at the foreground and then commit.
Test Demo
Front desk:
@using (Html.BeginForm ()) { <input type= "text" id= "JSON" name= "json"/> <input type= "Submit" Value= "Commit"/> }<script> var json = [{"Name": "Small Pony", "ID": 9, "Stock": "ABC"}]; Json.push ({"Name": "SpongeBob SquarePants", "ID": 8, "Stock": "XYZ"}) var jsonstr = json.stringify (JSON); $ (' #json '). Val (jsonstr); Alert (JSONSTR);</script>
Background:
[HttpPost] Public ActionResult Ajaxpager (string json) { JavaScriptSerializer js = new JavaScriptSerializer (); Jsonclass Jsonclass = (jsonclass) JS. Deserialize (JSON, typeof (Jsonclass));; var test = js. Deserialize (JSON, typeof (Jsonclass)); If it is a one-dimensional array of JSON with this //jsonclass JC = js. Deserialize<jsonclass> (JSON); Converts a multidimensional array into a list generic. list<jsonclass> JC = js. Deserialize<list<jsonclass>> (JSON); return View (); } } public class Jsonclass {public string Name {get; set;} public int ID {get; set;} public string Stock {get; set;} }
This makes it easy to handle.
Record it. Spare
In C #, the JSON string is converted to an object.