weixin_33720078 2013-12-04 19:28 采纳率: 0%
浏览 67

对Web Api的Ajax PUT请求

I currently have a ajax request setup to send a "PUT" request to a web api in my mvc 4 project. My request is able to get into the method on the api but the parameter is always null. Any ideas why? I have also check the PUT request as its executed and it does send a string of key/value pairs for each form control. Here is my code:

Web Api method (selection is always null)

public void Put([FromBody]string selection)
{
}

Update:

I forgot I was doing a little debugging of my own. I have confirmed that when you serialize a form the param is named "selection". Please take another look.

Ajax call:

$.ajax({
    type: "PUT",
    url: urlPrefix + "api/file/Manipulate",
    data: $("#frmManipulate").serialize(),
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    statusCode: {
        204: function (jqXHR) {
            alert("No file(s)/Directory(s) were selected.");
        }
    }
}).done(function () {
    location.reload();
});
  • 写回答

2条回答 默认 最新

  • weixin_33721427 2013-12-04 19:32
    关注

    It's null because you aren't passing it:

    data: { val1 : "test",  val2 : "test2"}
    

    Try:

    data: { selection : "something" }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何实验stm32主通道和互补通道独立输出
  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题