I have been struggling for a while and cannot seem to get this to work.
I have a Controller, say "Teacher".
I want a PUT action with a different name, but accepts [FromBody] a complex DTO.
How can I invoke it? Everything I tried is giving me a 404.
[Produces("application/json")]
[Route("api/Teacher")]
public class TeacherController : Controller
{
private readonly ITeacherService _teacherService;
public TeacherController(ITeacherService teacherService)
{
this._teacherService = teacherService;
}
[HttpPut("UpdateTeacherForInterview")]
public IActionResult PutTeacherForInterview(int id, [FromBody]UpdateInterviewModel model)
{
return Ok();
}
}
I have tried (and cried!):
PUT /api/Teacher/1 (and complex object)
PUT /api/Teacher/UpdateTeacherForInterview/1 (and complex object)
PUT /api/Teacher/PutTeacherForInterview/1 (and complex object)
I always get a 404.
The simple Put works i.e:
[HttpPut]
public IActionResult Put(int id, [FromBody]string value)
{
return Ok();
}
But I want to use a different action name.
Thoughts?
The route template was not matching the URL being called
//Matches PUT api/Teacher/UpdateTeacherForInterview/1
[HttpPut("UpdateTeacherForInterview/{id:int}")]
public IActionResult PutTeacherForInterview(int id, [FromBody]UpdateInterviewModel model) {
return Ok();
}
Reference Routing to Controller Actions
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