Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 未传递IActionResult参数_C#_Asp.net Core_Asp.net Core Mvc_Parameter Passing_Ngrok - Fatal编程技术网

C# 未传递IActionResult参数

C# 未传递IActionResult参数,c#,asp.net-core,asp.net-core-mvc,parameter-passing,ngrok,C#,Asp.net Core,Asp.net Core Mvc,Parameter Passing,Ngrok,我将以下请求发送到 http://somesite.ngrok.io/nexmo?to=61295543680&from=68889004478&conversation_uuid=CON-btt4eba4-dbc3-4019-a978-ef3b230e923a&uuid=2DDH8172JBC252E02FA0E994458111FDC 我的ASP.NET核心应用程序中的操作控制器方法是: [HttpPost] public IActionResult Index(string uuid) {

我将以下请求发送到

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

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

[HttpPost]
public IActionResult Index(string uuid)
{
    string s = uuid;
    return View();
}
返回
行设置断点时,为什么
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
值,我可以看到请求实际上已经发送到我的控制器操作…

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

[HttpPost]
public IActionResult Index([FromQuery]Model model) {
    if(ModelState.IsValid) {
        var uuid = model.uuid;
        string s = uuid;
        return View();
    }
    return BadRequest();
}
[FromHeader]
[FromQuery]
[FromRoute]
[FromForm]
:使用这些来指定要应用的确切绑定源

创建一个模型来保存这些值

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请求,您应该利用请求体来处理更复杂的类型,因为查询字符串比请求体更受限制


引用

因为您没有告诉操作期望从URI获取参数,所以无论如何都不应该使用查询字符串发布。查询字符串是URI的一部分,应该是幂等的,而POST本质上不是。您有一个带有POST-use命令的请求主体。