【问题标题】:AJAX Get with Web API 2 routingAJAX Get 与 Web API 2 路由
【发布时间】:2013-12-28 05:45:32
【问题描述】:

我正在尝试自学如何使用 web api 属性路由。当我使用帖子时它工作正常,但我无法获得使用参数的“get”方法

这是有效的帖子:

淘汰

self.ajaxTest = function () {
$.ajax("tasks", {
  data: ko.toJSON({ tasks: self.tasks }),
  type: "post", contentType: "application/json",
  success: function (result) { alert(result) }
});
};

API 控制器

[Route("documents/tasks")]
public string SubmitDocuments()
{
  return "test";
}

下面是失败的获取。我尝试了几种不同的方法。获取 url 似乎每次都会弄乱我的路由。

  self.ajaxTest = function () {
$.ajax("documents/checkForDocuments", {
  data: { test: "abc" },
  type: "get", contentType: "application/json",
  success: function (result) { alert(result) }
});
};

API 控制器

[Route("documents/checkForDocuments")]
public string CheckForDocuments(string test)
{
  return "test";
}

有什么建议吗?我只是做错了吗?无论我做什么,我似乎都无法使用 get 方法在 c# 中设置断点

【问题讨论】:

    标签: c# ajax knockout.js asp.net-web-api asp.net-mvc-5


    【解决方案1】:

    尝试用GET 替换您的Route 属性:

    [GET("documents/checkForDocuments/{test}")]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-24
      • 1970-01-01
      • 2015-05-21
      • 2018-08-25
      • 1970-01-01
      • 2016-07-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多