1

我正在尝试在 web api mvc4 中发布数据,但它没有从我在 HTML 中的所有字段中获取值。它获取的唯一值是来自 ID。请参阅下面的代码并为我提供一些解决方案。

$("#pst").click(function AddProduct() {
    //jQuery.support.cors = true;
    var item = {
        ID: $("#prodId").val(),
        Name: $("#name").val(),
        Price: $("#price").val,
        Category: $("#category").val()

    };

    $.ajax({
        url: 'http://localhost:49503/api/Products',
        type: 'POST',
        data: JSON.stringify(item),
        ContentType: "application/json;charset=utf-8",
        success: function (data) {
            alert('added Successfully');
        },
        error: function (x, y, z) {

            alert('not added');
        }

    });

});
4

0 回答 0