在反应中使用fetch时的null [FormBody]字符串值

问题描述 投票:0回答:1

我在.js文件中有以下提取

    fetch('api/SampleData/GetBpmnXml', {
        method: 'post',

        body: {
            "first_name": "Bob"
        }
    })

在API我有这个帖子

    [HttpPost]
    public void Post([FromBody] string first_name)
    { return first_name;}

为什么返回值为null?而不是鲍勃?

c# reactjs api post fetch
1个回答
0
投票

请参阅body部分,参数名称为first_name,而不是api端点中的value。可能会将您的Api端点更改为以下;这样它就可以绑定到参数

[HttpPost]
public void Post([FromBody] string first_name)
{ return value;}
© www.soinside.com 2019 - 2024. All rights reserved.