[英]Web API Post get related data from json.stringify
I have an html page with a button on it. 我有一个带有按钮的html页面。 Here are the functions that are important:
以下是重要的功能:
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);
}
});
}
Here is the controller that handles the click: 这是处理点击的控制器:
' 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
'create the document header Dim otaSOPHdrIvcInsert As New Serialization.taSopHdrIvcInsert '将文档标题Dim otaSOPHdrIvcInsert创建为新的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
Here is where I'm stuck. 这就是我卡住的地方。 I need to loop through the SOP10200 (which are the order lines) and for each one do something like this:
我需要遍历SOP10200(这是订单行),并为每个人做这样的事情:
Dim otaSOPLineIvcInsert As New Serialization.taSopLineIvcInsert_ItemsTaSopLineIvcInsert
With otaSOPLineIvcInsert
.SOPNUMBE = strSopNumber
.SOPTYPE = 2
.DOCDATE = DateString
.ITEMNMBR = sOP10100.SOP10200.itemnmbr
End With
But I can't seem to be able to get to the itemnmbr
in code. 但是我似乎无法使用代码
itemnmbr
。 I can see it when debugging, so I know it is there. 我可以在调试时看到它,所以我知道它在那里。
If this wasn't coming from an API but a linq query I would do a query and then 如果这不是来自API,而是来自linq查询,我会进行查询,然后
For Each IV00101 In query
Any help on this would be greatly appreciated. 任何帮助,将不胜感激。 I know the code is in VB, but the problem also applies to C#.
我知道代码在VB中,但是问题也适用于C#。
You need to access the collection property SOP10200 to get access to it's items: 您需要访问集合属性SOP10200才能访问其项目:
For Each IV00101 IN sOP10100.SOP10200
'Do Work
Next
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.