ฉันกำลังอัปเดตบันทึกโดยใช้ PUT ใน web api เมื่อฉันใช้ contentType: 'application/json; charset=utf-8' ข้อมูลของฉันจะไม่ถูกส่งไปยังตัวควบคุม api แต่เมื่อฉันแสดงความคิดเห็น ข้อมูลบรรทัดนี้จะถูกถ่ายโอน ใครสามารถอธิบายเรื่องนี้ได้บ้าง? ด้านล่างคือการโทรของฉันจากมุมมอง mvc
$(function () {
$("#btnSubmit").click(function () {
var id = $("#hdnProductID").val();
var ProductName = $("#txtProductName").val();
var QuantityPerUnit = $("#txtQuantityPerUnit").val();
var ReorderLevel = $("#txtReorderLevel").val();
var UnitPrice = $("#txtUnitPrice").val();
var UnitsInStock = $("#txtUnitsInStock").val();
var UnitsOnOrder = $("#txtUnitsOnOrder").val();
$.ajax({
url: "http://localhost:2821/api/Products"+ "/" + id,
type: 'PUT',
contentType: 'application/json; charset=utf-8',
data:{ProductName:ProductName,QuantityPerUnit:QuantityPerUnit,ReorderLevel:ReorderLevel,UnitPrice:UnitPrice,UnitsInStock:UnitsInStock,UnitsOnOrder:UnitsOnOrder},
success: function (data) {
alert("success");
},
error: function (msg) {
alert(msg);
}
});
});
});
ด้านล่างนี้เป็นวิธีการควบคุมของฉัน
public IHttpActionResult PutProduct(int id, Product product)
{}
data:JSON.stringify({ProductName:ProductName,QuantityPerUnit:QuantityPerUnit,ReorderLevel:ReorderLevel,UnitPrice:UnitPrice,UnitsInStock:UnitsInStock,UnitsOnOrder:UnitsOnOrder})
- person T J   schedule 05.11.2015contentType: 'application/json; charset=utf-8',
ถูกต้องหรือไม่ คุณลองแค่contentType: 'application/json;
แล้วหรือยัง? ดูสิ่งนี้: stackoverflow.com/ คำถาม/477816/ - person zer00ne   schedule 05.11.2015data
- person t.niese   schedule 05.11.2015