Web API Post从json.stringify获取相关数据

时间:2017-04-05 20:32:33

标签: .net json vb.net web model-binding

我有一个带有按钮的html页面。以下是重要的功能:

function updateClick() {
    SOP10100 = new Object();
    SOP10100.CUSTNMBR = "5000";
    SOP10100.SHIPMTHD = "FedEX";
    SOP10100.SOP10200 = [{ itemnmbr: "120604", quantity: 3, unitprice: .98, uofm: "ROLL" }, { itemnmbr: "120604", quantity: 1, unitprice: 4.98, uofm: "6 ROLL" }, { itemnmbr: "120604", quantity: 2, unitprice: 10.98, uofm: "12 ROLL" }]

    salesOrderCreate(SOP10100);
}

function salesOrderCreate(sOP10100) {
   $.ajax({
        url: '/api/SOP10100',
        type: 'POST',
        contentType: "application/json;charset=utf-8",
        data: JSON.stringify(sOP10100),
        success: function (data) {
            salesOrderSuccess(data);
        },
        error: function (request, message, error) {
            handleException(request, message, error);
        }
    });
}

以下是处理点击的控制器:

' POST: api/SOP10100
<ResponseType(GetType(SOP10100))>
Function PostSOP10100(ByVal sOP10100 As SOP10100) As IHttpActionResult
    If Not ModelState.IsValid Then
        Return BadRequest(ModelState)
    End If

    Try

'创建文档标题             Dim otaSOPHdrIvcInsert As New Serialization.taSopHdrIvcInsert

        'populate the header
        With otaSOPHdrIvcInsert
            .DOCID = "EQ SALE ORD"
            .BACHNUMB = "webOrder"
            .LOCNCODE = "WAREHOUSE"
            .DOCDATE = DateString 'Today
            .CUSTNMBR = sOP10100.CUSTNMBR
            .SHIPMTHD = sOP10100.SHIPMTHD
            .REFRENCE = sOP10100.REFRENCE
    End With

这是我被困的地方。我需要遍历SOP10200(这是订单行),并为每个人做这样的事情:

Dim otaSOPLineIvcInsert As New Serialization.taSopLineIvcInsert_ItemsTaSopLineIvcInsert

With otaSOPLineIvcInsert
    .SOPNUMBE = strSopNumber
    .SOPTYPE = 2
    .DOCDATE = DateString
    .ITEMNMBR = sOP10100.SOP10200.itemnmbr
End With

但我似乎无法在代码中找到itemnmbr。我可以在调试时看到它,所以我知道它就在那里。

如果这不是来自API而是来自linq查询,我会进行查询然后

For Each IV00101 In query

对此的任何帮助将不胜感激。我知道代码是在VB中,但问题也适用于C#。

1 个答案:

答案 0 :(得分:0)

您需要访问集合属性SOP10200才能访问它的项目:

 For Each IV00101 IN sOP10100.SOP10200

      'Do Work

 Next