C# ASP.NET核心WebAPI 2 PUT方法名称
我已经挣扎了一段时间,似乎无法让这个工作 我有一个控制器,说“老师” 我想要一个具有不同名称的PUT操作,但接受复杂的DTO 我如何调用它?我试过的每件事都给了我一个404C# ASP.NET核心WebAPI 2 PUT方法名称,c#,asp.net-core-webapi,asp.net-core-routing,C#,Asp.net Core Webapi,Asp.net Core Routing,我已经挣扎了一段时间,似乎无法让这个工作 我有一个控制器,说“老师” 我想要一个具有不同名称的PUT操作,但接受复杂的DTO 我如何调用它?我试过的每件事都给了我一个404 [Produces("application/json")] [Route("api/Teacher")] public class TeacherController : Controller { private readonly ITeacherService _teacherService; publ
[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(和复杂对象)
PUT/api/Teacher/updateTech for Interview/1(和复杂对象)
PUT/api/Teacher/PutTeacherForInterview/1(和复杂对象)
我总是得到一个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();
}
参考资料@Ahmedilyas我刚开始时也是这样。这要归功于我的刻苦学习,这样你就不必这么做了。英雄联盟