前端写法:
var json = { "VendorId": strVendorId, "VendorName": strVendorName, "Remark": strRemark, "PurchaseOrderId": strPurchaseOrderId, "MatId":strMatId, "decThisTimeQty": decThisTimeQty };
$.ajax({
type: "POST",
url: "/PurchaseOrder/Add",
data: JSON.stringify(json),
dataType: "json",
success: function (data) { //回调函数,data为形参,是从login-cl.php页面返回的值
if (data.trim() == "OK") //trim()去空格
alert("添加成功");
else
alert("添加失败");
});
控制器里的写法:
using System.Web.Script.Serialization;
[HttpPost]
public JsonResult Add()
{
//获取ajax中的data数据转成json
var sr = new StreamReader(Request.InputStream);
string stream = sr.ReadToEnd();
JavaScriptSerializer js = new JavaScriptSerializer();
var mian = js.Deserialize<DeliveryOrder>(stream);
var detail = js.Deserialize<DeliveryOrderDetail>(stream);
不是完整的代码哦。。。。。
var data = new { msg = "Over size", code = 200 };
return Json(data);
}