如何在网络中使用 Put 方法 api

How to use Put method in web api

这是我的放置方法

         
        [Route("api/SPSOnHand/itemcode/{item_code}")]
        [HttpPut]
        public HttpResponseMessage Put(String itemcode, [FromBody]SPS_ONHAND _member)
        {
           
            var memberdetail = (from a in db.SPS_ONHANDs where a.ITEM_CODE == itemcode select a).FirstOrDefault();
  
            if (memberdetail != null)
            {
      
                memberdetail.ONHAND_QTY = _member.ONHAND_QTY;
                memberdetail.OPR_ID = _member.OPR_ID;
                memberdetail.DATE = _member.DATE;
 
                db.SubmitChanges();

                  
                return Request.CreateResponse(HttpStatusCode.OK, memberdetail);
            }
            else
            {
                  
                return Request.CreateErrorResponse(HttpStatusCode.NotFound, "Invalid Code or Member Not Found");
            }


        }

这是我在 fiddler 中测试的内容

我该怎么办..我想使用 itemcode 而不是 id

来更新我的 table

绑定参数必须与路由定义中的占位符同名。试试这个:

    [Route("api/SPSOnHand/itemcode/{item_code}")]
    [HttpPut]
    public HttpResponseMessage Put(string item_code, [FromBody]SPS_ONHAND _member)
    {  
         var memberdetail = (from a in db.SPS_ONHANDs where a.ITEM_CODE == item_code select a).FirstOrDefault();
         ....
    }