c# - 对 ASP.NET Core ApiController 的删除请求不起作用
问题描述
我有 apiController 如下所示。而且,我正在delete
通过邮递员发送请求。但是,我的删除请求无法访问方法。但是,get
方法工作得很好。这个错误的原因是什么?
我的邮递员网址是: http://localhost:5004/api/Student/DeleteStudent/23
[ApiController]
[Route("api/[controller]/[action]")]
public class StudentController : ControllerBase
{
[HttpDelete("DeleteStudent/{studentId}")]
public async Task<ServiceResult> DeleteStudent(long studentId)
{
return await studentService.DeleteStudent(studentId);
}
[HttpGet]
public async Task<ServiceResult> GetStudents(int studentType)
{
return await studentService.GetStudents(studentType);
}
}
解决方案
使用[HttpDelete("{studentId}")]
代替[HttpDelete("DeleteStudent/{studentId}")]
onDeleteStudent()
方法如下:
[HttpDelete("{studentId}")]
public async Task<ServiceResult> DeleteStudent(long studentId)
{
return await studentService.DeleteStudent(studentId);
}
我已经在一个测试项目中对其进行了测试,Postman
并且效果很好!
推荐阅读
- matlab - U Net 纹理分割(验证数据集)
- javascript - 如何初始化 i18next
- reactjs - 当我添加 useFirestoreForProfile 和 userProfile 时,我的“用户”集合没有出现在我的控制台中
- c - 我正在尝试找到一种方法让我的服务器套接字打开,直到连接的客户端发送他想要的所有消息
- python - 处理多个用户发送命令
- python - 您如何获得 statsModels 中测试数据的调整后 R 平方?
- java - 如何修复此 Firebase RunTime DB 错误,其中创建了数据库条目和身份验证详细信息,但所有字段均为空?
- javascript - 为什么 Koa 的重定向在另一个重定向之后抛出 404?
- angular - Angular 10 Web Worker:找不到基本 TypeScript 配置文件“tsconfig.base.json”
- c# - 循环遍历 C# 列表