【发布时间】:2017-04-14 08:32:17
【问题描述】:
我已经在我的 API 控制器上声明了一个函数:
[HttpGet, Authorize]
public List<UIPhotoModel> GetPhotosByAlbumID(int AlbumID)
{
....
}
我从我的 javascript 调用它:
var urinocat = '/api/Photo/GetPhotosByAlbumID';
$.get({ url: urinocat, contentType: "application/json" }, 0)
.done(function (data) {
vm.UncategorisedImages(data);
});
得到:
GET http://localhost:54065/api/Photo/GetPhotosByAlbumID 404 (Not Found)
我知道如何解决它的唯一方法是创建一个包含 int 的类,并在我的控制器方法中传递接受它。为什么找不到 API 方法?
所有其他的都可以使用我使用一个复杂的对象并将该 bk 传递给控制器。但是一个 int - 它失败了。
【问题讨论】:
-
尝试将其作为字符串
"0"发送。文档说数据应该是A plain object or string that is sent to the server with the request.api.jquery.com/jquery.get。此外,由于您在服务器上有(int AlbumID),它将被解析为int.. -
你说的是.net web api吗?如果您使用默认路由,那么我认为您想要 GetPhotosByAlbumID(int id) 并且您的 url 将是 '/api/Photo/' + yourid ;
标签: javascript jquery asp.net-web-api knockout.js