[英]What is the purpose of this check in this PUT method of ASP.NET Core WebAPI with Entity Framework Core?
[英]ASP.NET Core WebAPI 2 PUT method name
我已经挣扎了一段时间,似乎无法让这个工作。
我有一个控制器,说“老师”。
我想要一个具有不同名称的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();
}
但我想使用不同的动作名称。
思考?
路由模板与被调用的URL不匹配
//Matches PUT api/Teacher/UpdateTeacherForInterview/1
[HttpPut("UpdateTeacherForInterview/{id:int}")]
public IActionResult PutTeacherForInterview(int id, [FromBody]UpdateInterviewModel model) {
return Ok();
}
参考路由到控制器操作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.