Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按id删除行在Asp.net核心web API+9中不起作用_Asp.net_Angular_Asp.net Core_Asp.net Web Api_Angular9 - Fatal编程技术网

按id删除行在Asp.net核心web API+9中不起作用

按id删除行在Asp.net核心web API+9中不起作用,asp.net,angular,asp.net-core,asp.net-web-api,angular9,Asp.net,Angular,Asp.net Core,Asp.net Web Api,Angular9,我试图通过将id从Angular 9+传递到ASP.NET核心Web API来删除该列,但我无法在控制器中点击。我在这里犯了什么错误?我正在使用表数据来运行SQL查询 控制器 类型脚本文件: deleteSettle(tid) { console.log(tid); // getting tid in console if (confirm('Are you sure to delete this record ? TID: '+ tid)) { this.s

我试图通过将id从Angular 9+传递到ASP.NET核心Web API来删除该列,但我无法在控制器中点击。我在这里犯了什么错误?我正在使用表数据来运行SQL查询

控制器

类型脚本文件:

deleteSettle(tid) {
    console.log(tid);  // getting tid in console

    if (confirm('Are you sure to delete this record ? TID: '+ tid)) {
        this.settlementService.deleteSettlement(tid).subscribe(
            (data: any) => {
                this.toastr.success("Successfully deleted");
            },
            err => {
               if (err.status == 400)
                  this.toastr.error('Server error or bad request', 'Error');
               else
                  this.toastr.error('Failed to check data', 'Server Error');
            }
      );
   }
}
错误:

删除https://localhost:44372/api/Settlement/DeleteById/355 404

您的路由路径已被此属性[HttpDelete{id}]覆盖

因此,只需删除Route属性并像这样添加属性

[HttpDelete("DeleteById/{id}")]
public IActionResult DeleteSettlementById(int id)
接下来,您需要删除方法参数中的[FromBody]属性,并这样编写

[HttpDelete("DeleteById/{id}")]
public IActionResult DeleteSettlementById(int id)

希望有帮助-快乐编码:

如果您有一个在数据库中执行删除的存储过程-为什么要使用ExecuteReader??这完全没有意义-您不希望返回需要读取的结果集。。。。。。只需使用ExecuteOnQuery即可!另外:在使用.Open之前,您应该将连接分配给SqlCommand对象-最好是在ConstructorHis.BaseURL中,它对于从angular调用的其他API具有相同的值?您可以从postman处调用此API吗?除了marc_的注释外,调用ExecuteOnQuery将返回受SQL语句影响的行数,因此,如果您想确认行已被实际删除,只需检查ExecuteOnQuery是否返回正值。@ChetanRanpariya this.BaseURL也是相同的值。邮递员错误:415不支持的媒体类型