Ajax数组列表传递

时间:2015-10-01 03:51:03

标签: arrays ajax vb.net

我试图在一个ajax调用中传递多个数组列表。有人可以帮助我吗?

阵列

var arraylist = [{name: name1, age: age1}, {name: name2, age: age2}, ...]

AJAX

$.ajax({
        url: "api/postProductLink",
        contentType: "application/json",
        type: "POST",
        data: { Info: arraylist},
        dataType: "json",
        success: function (result) {

        }
    });

后端vb.net

<HttpPost>
<POST("api/postProductLink")> _
Public Function postProductLink(data As ProductMerchandiseModel) As ResponseCallBack
    'code here
End Function

模型

Public Class ProductMerchandiseModel
Public name As String
Public age As Integer End Class

我想单独提取每个名字和年龄。

谢谢!

1 个答案:

答案 0 :(得分:0)

您的AJAX调用应如下所示:

$.ajax({
    url: "api/postProductLink",
    contentType: "application/json",
    type: "POST",
    data: JSON.stringify(arrayList),// Since your contentType is JSON.
    dataType: "json",
    success: function (result) {

    }
});