【发布时间】:2019-10-03 23:15:25
【问题描述】:
我正在尝试使用调用 .Net REST API 的 PUT 请求更新数据。当我发送 AJAX 调用时,它显示 404 错误。
var url = "http://localhost/site/mycontrollerName/PUT"
$.ajax({
url: url,
type: "PUT",
contentType: 'application/json',
dataType: "json",
data: {
"userId": userid ,
"paramDate1":date1 ,
"eventId1": _event1 ,
"paramDate2": date2 ,
"eventId2": _event2
},
success: function (data) {
// some task
}
, fail: function () {
// some task
}
})
[HttpPut]
public JsonResult PUT(int userId, DateTime paramDate1, int eventId1, DateTime paramDate2, int eventId2)
{
var response = "";
return Json(response, JsonRequestBehavior.AllowGet);
}
这里有什么问题?我还尝试为参数创建一个数组并将它们作为 JSON 字符串传递。我还尝试了以下 URL,删除了 userid 参数:
http://localhost/site/mycontrollerName/1/PUT
和
http://localhost/site/mycontrollerName/PUT/1
【问题讨论】:
-
评论不用于扩展讨论;这个对话是moved to chat。
标签: jquery ajax asp.net-mvc http http-put