我有如下所示的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);
}
}
答案 0 :(得分:2)
在[HttpDelete("{studentId}")]
方法上使用[HttpDelete("DeleteStudent/{studentId}")]
代替DeleteStudent()
,如下所示:
[HttpDelete("{studentId}")]
public async Task<ServiceResult> DeleteStudent(long studentId)
{
return await studentService.DeleteStudent(studentId);
}
我已经在Postman
的测试项目中对其进行了测试,并且效果很好!