未传递 IActionResult 参数

IActionResult parameter not being passed

我正在向

发送以下请求

http://somesite.ngrok.io/nexmo?to=61295543680&from=68889004478&conversation_uuid=CON-btt4eba4-dbc3-4019-a978-ef3b230e923a&uuid=2ddh8172jbc252e02fa0e99445811fdc

我的 ASP.NET 核心应用程序中的动作控制器方法是:

[HttpPost]
public IActionResult Index(string uuid)
{
    string s = uuid;
    return View();
}

return行设置断点,为什么s = null?它应该等于 2ddh8172jbc252e02fa0e99445811fdc.

更新

添加 [FromQuery] 似乎不起作用。我联系了 API 团队,他们回复我说这是他们发布到我的 url:

的信息
"HTTP-METHOD=POST"
"HTTP-RESP=callback response is ignored"
"CONVERSATION-ID=CON-81593cc2-cba0-49e7-8283-f08813e1a98e"
"HTTP-REQ={from=61400104478, to=61290567680, uuid=8a4079c012c1bfa23f6dff8485e27d00, conversation_uuid=CON-81593cc2-cba0-49e7-8283-f08813e1a98e, status=started, direction=inbound, timestamp=2018-08-31T15:05:02.729Z}"

这些信息对您有帮助吗?也许我必须反序列化一些东西?我不会这么想,但我不明白为什么我没有检索 uuid 值,而且我可以看到请求实际上已经完成了我的控制器操作...

因为您没有告诉操作期望查询字符串中的参数

[FromHeader], [FromQuery], [FromRoute], [FromForm]: Use these to specify the exact binding source you want to apply.

创建一个模型来保存值

public class Model {
    public string uuid { get; set; }

    //...other properties
}

并更新操作以使用 [FromQuery] 根据查询字符串中提供的键值绑定模型

[HttpPost]
public IActionResult Index([FromQuery]Model model) {
    if(ModelState.IsValid) {
        var uuid = model.uuid;
        string s = uuid;
        return View();
    }
    return BadRequest();
}

理想情况下,对于 POST 请求,您应该利用请求 BODY 处理更复杂的类型,因为查询字符串比请求正文更受限制。

引用Model Binding in ASP.NET Core