I have .net core WebApi like below. And it is working perfectly. But, when I write [HttpDelete] instead of [HttpDelete("{id}")] , then it doesn't work. What can be reason ?
My url : 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);
}
}
Without the {id} route template parameter, the only other way to populate the value would be via query string
http://localhost:5004/api/Student/DeleteStudent?id=23
The route table will match the querystring parameter to the action parameter to make the match.
Either way, the id needs to be provided to know which action to call and which record to delete.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With