尝试使用axios .NET API和ReactJS进行PUT时出错

时间:2019-11-13 16:50:33

标签: reactjs axios

我有一个ReactJS项目,并且我在数据库中使用.NET api。我有一个杂货清单应用程序,问题是当我得到 PUT https://localhost:5001/inventory/2 400(错误请求)时,无法使用axios.put更新当前可用的杂货产品。

我用来处理更新的输入方法:

onSubmit(e) {  
    e.preventDefault() 
    const obj = {  
      name: this.state.Name,  
      price: this.state.Price,  
      description: this.state.Description
    };  
    axios.put('https://localhost:5001/inventory/' + this.props.match.params.id, obj)
        .then(res => console.log(res.data));  
        this.props.history.push('/Fetch-Data')  
  } 

Controller.cs:

[HttpPut("{id}")]
        public async Task<Inventory> Put(Inventory updateInventory){
            _context.Update(updateInventory);
            await _context.SaveChangesAsync();
            return updateInventory;
        } 

端子:

info: Microsoft.AspNetCore.Routing.EndpointMiddleware[1]
      Executed endpoint 'pgr320_eksamen.Controllers.InventoryController.Put (pgr320-eksamen)'
info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
      Request finished in 1.6168ms 400 application/problem+json; charset=utf-8

正如您在此处看到的那样,我指的是要更新的ID。 任何帮助将不胜感激!

0 个答案:

没有答案