如何将对象列表传递给 Web API get 方法? 我并不是想发布这个列表,只是想对这个数据进行一些函数并返回一个值。
我尝试了以下代码:
[Route("Save_SALE")]
[HttpGet]
[AllowAnonymous]
public IHttpActionResult Save_SALE(List<SL_table> SL_table)
{
return Ok(SL_table);
}
它似乎返回空列表。谁能告诉我怎么了?
1) 无法使用“Httpget”传递数据 2)json数据必须与你的类字段相同
示例 json 数据:
[
{
"date": "2020-11-01T10:47:25",
"checkNo": "2020300400474",
"siteNo": "2001",
"siteName": "Koroglu",
"taxId": "0122345789",
"companyName": "AA Company MMC",
"amount": 30,
"description": "description main",
"description2": "description additional"
},
{
"date": "2020-11-06T11:17:38",
"checkNo": "2020300400479",
"siteNo": "2002",
"siteName": "20 yanvar",
"taxId": "0122345789",
"companyName": "AB Company MMC",
"amount": 240,
"description": "description main",
"description2": "description additional"
}
]
和示例 Web API 方法
[HttpPost]
public async Task<IActionResult> AddInvoice(List<Invoice> invoices)
{
return Ok(invoices)
}
如果您想使用 HttpGet 传递数据,则使用查询参数