【发布时间】:2019-04-29 03:15:47
【问题描述】:
我有如下所示的 .net 核心 WebApi。它运行良好。但是,当我写 [HttpDelete] 而不是 [HttpDelete("{id}")] 时,它就不起作用了。可能是什么原因?
我的网址:http://localhost:5004/api/Student/DeleteStudent/23
[ApiController]
[Route("api/[controller]/[action]")]
public class StudentController : ControllerBase
{
//[HttpDelete] ///////////////// This is not working
[HttpDelete("{id}")] /////////// This is working
public async Task<ServiceResult> DeleteStudent(int id)
{
return await studentService.DeleteStudent(id);
}
}
【问题讨论】:
-
MVC 如何知道从哪里获取 ID?为什么要移除路由模板?
-
我只发送一个参数。我想,它可以知道@PanagiotisKanavos
-
例如在本站; c-sharpcorner.com/article/…@PanagiotisKanavos 他没有使用 id 参数。
-
没有 id 路由模板参数,只有其他填充值的方法是通过查询字符串(即
http://localhost:5004/api/Student/DeleteStudent?id=23)。无论哪种方式,都需要提供 id 才能知道要删除哪条记录 -
谢谢@Nkosi。我想,这就是我要找的。有效。你能写为答案,我会标记为答案。
标签: c# angular asp.net-web-api