API後臺 WebApi FromBody參數 查看 https://blog.csdn.net/bafnypeu/article/details/78262684 ...
//獲取賬號名 var Name = document.getElementById("Text1").value;//獲取密碼 var Pass = document.getElementById("Password1").value; //獲取真實姓名 var Realname = document.getElementById("Text3").value; //獲取聯繫電話 var Telphone = document.getElementById("Text4").value; //獲取用戶狀態 var Status = 0; //判斷單選框是否選中 var val = $("input:radio[name='qi']:checked").val(); if (val == null) { alert("您沒有選擇狀態"); } else { //創建一個類 var userInfo = { Name: Name, Pass: Pass, Realname: Realname, Telphone: Telphone, Status: parseInt(val) } //調用方法 $.ajax({ url: "Api地址", type: "POST",
//將類轉換為json字元串 data: JSON.stringify(userInfo), dataType: "json", contentType: "application/json;charset=utf-8", success: function (data) { if (data > 0) { alert("添加成功"); } else { alert("添加失敗"); } } }) }
API後臺
//API代碼
[HttpPost] public int Post([FromBody]UserInfo userInfo) { return bll.AddUser(userInfo); }
WebApi FromBody參數
查看 https://blog.csdn.net/bafnypeu/article/details/78262684