發生了一些不可思議的事情......並且我不太明白爲什麼...... 只有將id參數類型從int更改爲object,此帖才能工作。這裏有什麼問題? webapi + angular + post
我所知道的最好的方法是在URL中設置的值...但是,我試圖避免這件事情......我的偏好是張貼值JSON
公共IHttpActionResult Gettest(INT ID) =不工作!
{「消息」:「沒有HTTP資源發現匹配的請求URI‘http://localhost:23052/api/testAPI/Gettest’。」,「MessageDetail」:「無動作被在控制器‘testAPI’與請求匹配找到」}
公共IHttpActionResult Gettest(對象ID)=它的工作原理
這個運行不錯
我是什麼樂隊g錯了?....我嘗試在服務器/客戶端將參數名稱從「id」更改爲「x」,並得到了相同的結果。
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);
});
角度支柱
如果您嘗試使用「int?'而不是? – juharr
它沒有工作...:S ...我剛剛試過 –
更改爲公共IHttpActionResult Gettest([FromUri] int id) –