【问题标题】:Value cannot be null. Parameter name: value, while calling httppost via ajax post值不能为空。参数名称:value,同时通过ajax post调用httppost
【发布时间】:2016-01-17 19:26:17
【问题描述】:

我正在尝试接收带有一些 json 字符串的发布请求

var contentType ="application/x-www-form-urlencoded; charset=utf-8";
$.ajax({
              type: "POST",
              data: JSON.stringify(fileData),
              url: "http://hercules/JsonTest/api/Getjson/sendData",
              contentType: contentType,
              processData: false,
              error: function (qXHR, textStatus, errorThrown) {
                  alert("failure: " + qXHR.status + ":" + textStatus + errorThrown);
              },
              success : function(data) {
                  alert("Success : " + data);
              }
          });

在我的 webapi 中

[System.Web.Http.HttpPost]
        [System.Web.Http.ActionName("sendData")]
        public string sendData([FromBody] string jsonString)
        {
            logData("Entering SendData : " + jsonString);
            return "Success";
        }

但是,webapi 中没有收到我发布的 jsonString。它抛出错误值不能为空。 参数名称:值

可能是什么原因。 我直接在我的视觉工作室中测试代码,同样工作正常。但是一旦我在机器上发布了相同的内容,并尝试通过 jsFiddle 访问,则字符串显示为空。

【问题讨论】:

    标签: asp.net-web-api


    【解决方案1】:

    我解决了这个问题。 在我的 ajax 发布请求中,我修改了

    数据:JSON.stringify(fileData),数据:'=' + 文件数据,

    加上equal,MVC的HTTPPOST方法正确接收数据。

    谢谢...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-16
      • 2014-05-17
      • 2016-05-14
      相关资源
      最近更新 更多