【发布时间】:2018-08-10 18:58:02
【问题描述】:
我已经苦苦挣扎了一段时间,似乎无法让它发挥作用。
我有一个控制器,说“老师”。
我想要一个具有不同名称的 PUT 操作,但接受 [FromBody] 一个复杂的 DTO。
如何调用它?我尝试的一切都是给我一个 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();
}
}
我试过了(哭了!):
PUT /api/Teacher/1 (and complex object)
PUT /api/Teacher/UpdateTeacherForInterview/1 (and complex object)
PUT /api/Teacher/PutTeacherForInterview/1 (and complex object)
我总是得到 404。
简单的 Put 工作,即:
[HttpPut]
public IActionResult Put(int id, [FromBody]string value)
{
return Ok();
}
但我想使用不同的动作名称。
想法?
【问题讨论】:
标签: c# asp.net-core-webapi asp.net-core-routing