私のajax呼び出しは次のようになります
$.ajax({ //actually approve or reject the promotion
url: url,
type: "POST",
data: '{'+data.PromotionId+','+data.UserId+','+data.ReasonText+'}',
dataType: "json",
//contentType: "application/json; charset=utf-8",
success: function (data) {
if (indicator == 'A') {
alert('Promotion approved successfully!');
}
else {
alert('Promotion rejected successfully.');
}
var homelink = '<%: Url.Action("Index","Home") %>';
window.location.href = (homelink);
returndata = data;
},
error: function (xhRequest, ErrorText, thrownError) {
alert("Failed to process promotion correctly, please try again");
console.log('xhRequest: ' + xhRequest + "\n");
console.log('ErrorText: ' + ErrorText + "\n");
console.log('thrownError: ' + thrownError + "\n");
}
});
そして、私のMVCコントローラーは次のようになります。
[HttpPost]
public HttpResponseMessage ApprovePromotion(PromotionDecision decision)
{
if (ModelState.IsValid && decision != null)
{
bool status = PromotionBo.ApprovePromotion(decision);
if (status == true)
return new HttpResponseMessage(HttpStatusCode.OK);
}
return new HttpResponseMessage(HttpStatusCode.BadRequest);
}
私はこれらの両方で構文が正しいと思っていましたが、ajax呼び出しを行うたびに400応答が返されます。私が間違っているのは何ですか?