Web API模型绑定祸患

时间:2018-06-06 22:58:44

标签: c# asp.net-core fetch asp.net-core-webapi

我正在努力将一些数据发布到网页上......

[HttpPost("{id:int}/stuff")]
public IActionResult Add([FromBody] viewModel viewModel, [FromRoute] int id)

取电话......

    fetch("api/" + id + "/stuff", {

                headers: {
                    'Accept': 'application/json, text/plain, */*',
                    'Content-Type': 'application/json'
                },
                credentials: "same-origin",
                method: "POST",
                data: JSON.stringify({ text: text })

            })

查看模型

public class ViewModel
{
    [JsonProperty(PropertyName = "t")]
    public string Text { get; set; }
}

Id是正确的,但viewModel null

下一步是什么?

0 个答案:

没有答案