我收到了以下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());
}
看起来控制器正在被两个请求命中,但是,第一个动作没有被击中?
答案 0 :(得分:2)
您必须传递等同于Int64 umbrellaId
的查询字符串或将其默认值设置为零。
答案 1 :(得分:0)
尝试更改以下网址:
url: "/Express2/api/BenefitBank/RevertTransactionUmbrella"
到:
url: "/Express2/api/BenefitBank/PostRevertSingleTransaction"