【问题标题】:Ajax Delete gives 405 method not allowed after publishAjax Delete 在发布后给出不允许的 405 方法
【发布时间】:2013-12-29 16:19:18
【问题描述】:

我尝试从桌子上移走一辆车。 这在发布后在本地主机(Visual Studio)上运行良好,我得到消息 405 方法是不允许的。

http://localhost:41904/api/vehicles/42

发布后:

DELETE http://myurl.com/api/vehicles /42 405 Method Not Allowed

我要删除的ajax方法:

      function reply_clic(clicked_id) {
      if (confirm("Systeem verwijderen?")) {
          $.ajax({
              url: '/api/' + clicked_id,  // RIS_POST_vehicle connected to button ID
              type: 'Delete',
              success: function (result) {
                  console.log('Joepie') // Do something with the result
                  $("#vehicleList").empty();
                  // bootbox.alert("Die is weg !!!");
                  loadvehicle()
              }
          });
      }
  }

控制器:

 public HttpResponseMessage Deletevehicle(int id)
    {
        vehicle vehicle = db.vehicle.Single(v => v.id_vehicle == id);
        if (vehicle == null)
        {
            return Request.CreateResponse(HttpStatusCode.NotFound);
        }

        db.vehicle.DeleteObject(vehicle);

        try
        {
            db.SaveChanges();
        }
        catch (DbUpdateConcurrencyException)
        {
            return Request.CreateResponse(HttpStatusCode.NotFound);
        }

        return Request.CreateResponse(HttpStatusCode.OK, vehicle);
    }

    protected override void Dispose(bool disposing)
    {
        db.Dispose();
        base.Dispose(disposing);
    }

有人建议吗?

【问题讨论】:

    标签: ajax json api asp.net-mvc-4 razor


    【解决方案1】:

    【讨论】:

    • 感谢这份清单!不幸的是我没有解决办法。对于“PUT”,您也可以在控制器中使用 Post,我希望在我的控制器中找到解决方案..
    • “我没有解决方案”是否意味着您没有对 IIS 的管理访问权限来重新配置它?
    猜你喜欢
    • 1970-01-01
    • 2019-07-29
    • 1970-01-01
    • 2021-02-04
    • 1970-01-01
    • 1970-01-01
    • 2023-02-17
    • 2020-03-19
    • 1970-01-01
    相关资源
    最近更新 更多