方案
我通过json将数组列表传递给api方法。调用成功,当我们看到列表时,它显示了传递的对象数量,但是对象中的值没有设置请求帮助。
我的对象:
var datavalue = [{
BeerId: 1,
BeerName: "KingFisher",
XCoordinates: 45,
YCoordinates: 56
},
{
BeerId: 2,
BeerName: "KingFisher(Strong)",
XCoordinates: 47,
YCoordinates: 58
}];
我的json电话:
$.ajax({ //actually approve or reject the promotion
url: 'api/BeerAppGroup/GetRegistered',
type: "POST",
data: JSON.stringify(datavalue),
contentType: "application/json; charset=utf-8",
success: function (data) {
}});
我的api方法:
[EnableCors("*", "*", "GET, POST")]
[HttpPost]
public IHttpActionResult GetRegistered(List<UserBeerDetailContact> datavalue)
{
BeerAppUserClass beerAppDal = new BeerAppUserClass();
return Json(new KeyValuePair<String, String>("IsRegistered", ""));
}
班级定义:
[Serializable]
public class UserBeerDetailContact
{
public Int32 BeerId { get; set; }
public String BeerName { get; set; }
public Int32 XCoordinates { get; set; }
public Int32 YCoordinates { get; set; }
}
我们在列表中得到计数2。但是每个对象中的值都是null。
请帮助如何获取值。
答案 0 :(得分:0)
var invoiceObj = {};
invoiceObj["InvoiceId"] = 0;
invoiceObj["BuyerName"] = $("#txtByerName").val();
invoiceObj["BuyerEmail"] = $("#txtByerEmail").val();
invoiceObj["InvoiceNumber"] = $("#txtInvoiceNo").val();
invoiceObj["InvoiceDate"] = $("#txtInvoiceDate").val();
invoiceObj["InvoiceDueDate"] = $("#txtInvoiceDueDate").val();
invoiceObj["InvoiceCurrency"] = $("#ddlCurency").val()
invoiceObj["Reference"] = $("#txtRef").val();
invoiceObj["InvoiceTotal"] = Total;
JSON.stringify(invoiceObj),
尝试使用上面的代码制作你的javascript对象,然后使用JSON对象
进行字符串化