から働いていませんこんにちは、私は、しかし、私はエラーを取得していますトラブルWEBAPIアクションメソッドへのAjaxのポストをやって過ごしています:はWEBAPI POST AJAX呼び出し
以下{"Message":"No HTTP resource was found that matches the request URI ...","MessageDetail":"No action was found on the controller that matches the request."}
は私のAJAX呼び出しです:
$.ajax({
url: "http://localhost/SomeService/api/ControllerName/TestPostMethod",
type: "POST",
data: JSON.stringify({ userId: "testuser', loc: "test" }),
contentType: "application/json;charset=utf-8",
success: function (msg) {
returnVal = msg;
},
error: function (xhr, msg) {
var response = JSON.parse(xhr.responseText);
if (xhr.readyState == 4) {
if (xhr.status != 401) {
if (response.Message) {
console.log(response.Message);
}
}
} else {
if (response.Message) {
console.log(response.Message);
}
}
}
});
以下、私のWebAPIの方法である:
[System.Web.Http.HttpPost()]
public HttpResponseMessage TestPostMethod([FromUri]string userId, string loc)
{
return Request.CreateResponse<string>(HttpStatusCode.OK, "success");
}
これはルートが設定されている方法です。
config.Routes.MapHttpRoute(
name: "DefaultApi",
routeTemplate: "api/{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional },
constraints:null
);
は、ここに私の答えが見つかりました:をhttp://stackoverflow.com/questions/13473334/getting-no-action-was-found-from-webapi – desiguy
'TestPostMethod'メソッドでモデルを定義してデータを送信する必要があります。 –