ajax:ajax
1:json
var chemicalsModel = { Chemicals: tableData, Id: id }; var jsonData = JSON.stringify(chemicalsModel); $.ajax ({ traditional: true, type: "POST", url: "/DataManage/SaveChemicals", data: jsonData, dataType: "json", contentType: "application/x-www-form-urlencoded; charset=UTF-8", success: function (data) { $("#loading-div").hide(); $(".loading-img").hide(); if (data.message == "success") { alert("保存成功"); } else { alert(data.message); } } });
[HttpPost] public ActionResult SaveChemicals() { var stream = HttpContext.Request.InputStream; string json = new StreamReader(stream).ReadToEnd(); System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); ChemicalsModel chemicalsModel = js.Deserialize<ChemicalsModel>(json); return Json(new { message = "success" }); }
2app
<form action="" method="post" name="form1" id="myform"> <input type="hidden" id="hiddenval" name="hiddenval" value="" /> <input type="hidden" id="hiddenids" name="hiddenids" value="" /> </form>
public ActionResult SetColumn(string id = "", string hiddenval = "", string hiddenids = "",string url="") { }