【发布时间】:2019-02-15 13:42:22
【问题描述】:
据我了解,.NET Core MVC中的常规路由是[controller]/[action]/{id?}
但是,我正在尝试捕获以下 POST 请求,如下所示:
myDomain/MyController/MyAction/userID/anotherID/myInfo
我尝试了以下方法,但似乎不起作用:
public class MyController : Controller
{
[HTTPPost]
[Route("MyAction/{userID:minlength(2)}/{anotherID:int}/myInfo")]
public IActionResult MyAction([FromRoute] string userID, [FromRoute] int anotherID, [FromBody] string stuffIWant)
{
return Ok();
}
}
显然我没有正确处理路由,但我不确定如何从该路由获得userID 和anotherID。我已将此操作发布到我的网站,并尝试使用相同的 URL 发布测试帖子,但没有得到响应。
【问题讨论】:
标签: c# routing asp.net-core-mvc