我不是想做REST。我想要这个:
public class MyV2Controller
{
[HttpPost]
public Task<UserModel> Action1([FromBody] FirstModel firstModel)
{ }
[HttpPost]
public Task<UserModel> Action2([FromBody] SecondModel secondModel)
{ }
}
路线应与此对齐:
http://localhost:1234/api/v2/my/action1/
http://localhost:1234/api/v2/my/action2/
我尝试了许多不同的路由配置(包括属性路由的各种组合),但似乎没有任何工作。我该怎么做才能做到这一点?
答案 0 :(得分:1)
Using Route attribute
[RoutePrefix("api/v2/my")]
public class MyV2Controller
{
[HttpPost]
[Route("action1")]
public Task<UserModel> Action1([FromBody] FirstModel firstModel)
{ }
[HttpPost]
[Route("action2")]
public Task<UserModel> Action2([FromBody] SecondModel secondModel)
{ }
}