Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/14.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
C# Web API HttpDelete-如何调用delete API方法并在[FromBody]中发送模型_C#_Asp.net Mvc_Asp.net Web Api2_Webapi_Http Delete - Fatal编程技术网

C# Web API HttpDelete-如何调用delete API方法并在[FromBody]中发送模型

C# Web API HttpDelete-如何调用delete API方法并在[FromBody]中发送模型,c#,asp.net-mvc,asp.net-web-api2,webapi,http-delete,C#,Asp.net Mvc,Asp.net Web Api2,Webapi,Http Delete,我试图通过在url中发送参数来调用HttpDelete restful web API方法。呼叫成功 范例 string url = path + "deletemethodName?Id=" + Convert.ToInt32(idpamameter) + "&name=" + nameParameter; using (HttpClient client = new HttpClient())

我试图通过在url中发送参数来调用HttpDelete restful web API方法。呼叫成功

范例

string url = path + "deletemethodName?Id=" + Convert.ToInt32(idpamameter) + "&name=" + nameParameter;
                using (HttpClient client = new HttpClient())
                {
                    using (HttpResponseMessage response = client.DeleteAsync(url).Result)
                    {
                        if (response.IsSuccessStatusCode)
                        {
                            return Json(response.Content.ReadAsStringAsync().Result);
                        }
                       }
                }
在调用HttpDelete方法时,有没有一种方法可以访问模型数据,而不是在URL中发送模型数据,就像我们使用在主体中发送的模型数据调用POST方法一样

由于我的HttpDelete方法中有5个以上的参数要附加到URL中,所以我希望发送一个模型数据


提前感谢。

更高级别的
deleteAscync
不支持主体,但我们可以“长期”支持主体:


您可以通过post方法删除记录。 如果您以表格格式显示记录,则us Foreach循环和该循环内使用Html格式,如下所示:

使用(Html.BeginForm(“ACTIONNAME”、“CONTROLLERNAME”、new{id=item.id,…}))

然后加上

 <input typer="submit" value="Delete"/>


将数据发布到您的操作控制器。

谢谢您的尝试。这不会影响性能知道吗?
 <input typer="submit" value="Delete"/>