1

我有以下 AJAX 请求:

var recordToRevert = $(this);
var umbrellaId = $(this).data("id");
var requestData = {
    umbrellaId: umbrellaId,
};

$.ajax({
    url: "/Express2/api/BenefitBank/RevertTransactionUmbrella",
    type: "POST",
    dataType: 'json',
    contentType: 'application/json; charset=utf-8',
    data: JSON.stringify(requestData),
    headers: {
        "Authorization-Token": "7,181,22",
        "CentreNumber": "0"
    }
}).done(function (data) {
    if (data.FoundRevertableTransactions) {
        recordToRevert.parent().html("<span class=\"success\">Reverted</span)");
    } else {
        alert('Umbrella NOT reverted');
    }
}).fail(function () {
    alert('Umbrella NOT reverted');
});

我在这里将它发送到 MVC 控制器/动作:

[HttpPost]
[ActionName("RevertTransactionUmbrella")]
public HttpResponseMessage PostRevertTransactionUmbrella(Int64 umbrellaId)
{
    if (ModelState.IsValid)
snip...

这是我得到的回应。

{"Message":"No HTTP resource was found that matches the request URI 'http://localhost/Express2/api/BenefitBank/RevertTransactionUmbrella'.","MessageDetail":"No action was found on the controller 'BenefitBank' that matches the request."}

我已经设置了一个断点并且控制器动作没有被命中。我想知道我是否没有正确发送 JSON?

这个请求虽然有效:

$.ajax({
    url: "/Express2/api/BenefitBank/GetRequestObjects",
    type: "GET",
    dataType: 'json',
    contentType: 'application/json; charset=utf-8',
    //data: JSON.stringify(requestData),

[HttpGet]
[ActionName("GetRequestObjects")]
public HttpResponseMessage GetRequestObjects()
{
    return Request.CreateResponse(HttpStatusCode.Accepted, new BenefitBankRequestObjects());
}

看起来控制器在两个请求上都被击中,但是,第一个请求没有被击中?

4

2 回答 2

2

您必须传递等效于Int64 umbrellaId或将其默认值设置为零的查询字符串。

于 2013-04-26T09:41:48.327 回答
0

尝试从以下位置更改 URL:

url: "/Express2/api/BenefitBank/RevertTransactionUmbrella"

至:

url: "/Express2/api/BenefitBank/PostRevertSingleTransaction"
于 2013-04-26T09:17:45.037 回答