Something strange is happening ... and I really don’t understand why ... This message only works if I change the type of the id parameter from int to object.
I know the best way is to set the value in the url ... however I tried to avoid this thing ... my preference is to post the values as json
public IHttpActionResult Gettest (int id) = not working!
{"Message": "No HTTP resource was found that matches the request URI" http: // localhost: 23052 / api / testAPI / Gettest '. "," MessageDetail ":" No actions were found on the controller "testAPI" that match the request. "}
public IHttpActionResult Gettest (object identifier) = it works
it works well
What am I doing wrong? .... I tried changing the parameter name from "id" to "x" on the server / client side, and I got the same result.
config.Routes.MapHttpRoute("DefaultActionApi", "api/{controller}/{action}/{id}", new { id = RouteParameter.Optional });
WebApiConfig.cs
[HttpPost]
public IHttpActionResult Gettest(int id)
{
test test = db.tests.Find(id);
if (test == null)
{
return NotFound();
}
return Ok(test);
}
testAPIController.cs
$http.post("/api/testAPI/Gettest", id)
.success(function (result) {
$scope.test = result;
}).error(function (result) {
console.log(result);
});
angular post
source
share