我将此 URI 传递给我的 Web API 服务器:
http://localhost:28642/api/InventoryItems/PostInventoryItem?serialNum=8675309e9&ID=147&pksize=2&Description=juanValdes&vendor_id=venderado&UnitCost=2.58&UnitList=3.82&OpenQty=25.70&UPC=12349&dept=139&subdept=89&upc_pack_size=24&vendor_item=popTartz&crv_id=157
此控制器代码(带有“[FromBody]”注释)不起作用:
public void PostInventoryItem([FromBody] string serialNum, [FromUri] InventoryItem ii)
{
string serNum = serialNum;
_inventoryItemRepository.PostInventoryItem(serNum,
ii.ID, ii.pksize, ii.Description, ii.vendor_id, ii.UnitCost, ii.UnitList, ii.OpenQty,
ii.UPC, ii.dept, ii.subdept, ii.upc_pack_size, ii.vendor_item, ii.crv_id);
}
...(序列号为空);但这(没有“[FromBody]”注释)确实:
public void PostInventoryItem(string serialNum, [FromUri] InventoryItem ii)
{
string serNum = serialNum;
_inventoryItemRepository.PostInventoryItem(serNum,
ii.ID, ii.pksize, ii.Description, ii.vendor_id, ii.UnitCost, ii.UnitList, ii.OpenQty,
ii.UPC, ii.dept, ii.subdept, ii.upc_pack_size, ii.vendor_item, ii.crv_id);
}
(serialNum 是预期的“8675309e9”)为什么?有人会认为更具体的版本会起作用,但尽管它可以编译,但对于第一个片段,serialNum 为空。
我知道您不能在一种方法中使用两个“[FromBody]”注释,如此处所述,但是是否不允许所有其他注释?