将JSON对象发送到ASPNET控制器方法,主体内容为null

时间:2018-08-02 14:58:04

标签: javascript c# asp.net-core

我试图弄清楚如何使用列出的AJAX POST请求发送的JSON对象的主体。 调试时,会调用UploadJSON方法,但它的jsoninput包含空内容。

 //ASP.NET Core
    [HttpPost]
    public IActionResult UploadJSON([FromBody] IFormCollection jsoninput)
    {

        var inputBody = jsoninput;


        // Writing JSON object content into a file....

        return RedirectToAction("Index");

    }

//javascript
            function uploadJSON(plistArrayForJSON) {
            var sendobj = JSON.stringify({ plistArrayForJSON });
            $.ajax({
                url: 'https://localhost:5001/home/uploadjson',
                type: 'POST',
                data: sendobj,
                contentType: "application/json",
            });
        }

1 个答案:

答案 0 :(得分:-1)

您发送的JSON无法反序列化为IFormCollection

//ASP.NET Core
[HttpPost]
public IActionResult UploadJSON([FromBody] IList<PlayList> jsoninput)
{

    var inputBody = jsoninput;


    // Writing JSON object content into a file....

    return RedirectToAction("Index");

}