angular.js:13424 Error: [$resource:badcfg] Error in resource configuration for action `delete`
angular.js:13424 Error: [$resource:badcfg] Error in resource configuration for action `delete`
我正在尝试删除一个对象和 return 一个确实触发网络 api 控制器方法的列表,但随后出现错误
Expected response to contain an object but got an array (Request: DELETE
$scope.deleteProduct = function (productId) {
productResource.delete({
id: productId
}, function (data) {
$scope.products = data;
});
}
资源控制器
function productResource($resource) {
return $resource("/api/products/:id");
}
Web api 控制器
public IQueryable Delete(int id)
{
var repository = new ProductRepository();
return repository.Delete(id).AsQueryable();
}
这是对数据库的调用,其中 return 是产品列表。
internal List<Product> Delete(int Id)
{
IDbConnection connection;
using (connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Liberty"].ToString()))
{
var result = connection.QueryMultiple("DeleteProduct", new{prodId = Id}, commandType: CommandType.StoredProcedure);
var products = result.Read<Product>().ToList();
return products;
}
}
我怎么弄错了?
您可以将 DELETE 操作的 return 类型指定为数组,因为这是您的 Web API 控制器 returns:
function productResource($resource) {
return $resource("/api/products/:id", { }, {
'delete': {
method: 'DELETE',
isArray: true
}
});
}
我正在尝试删除一个对象和 return 一个确实触发网络 api 控制器方法的列表,但随后出现错误
Expected response to contain an object but got an array (Request: DELETE
$scope.deleteProduct = function (productId) {
productResource.delete({
id: productId
}, function (data) {
$scope.products = data;
});
}
资源控制器
function productResource($resource) {
return $resource("/api/products/:id");
}
Web api 控制器
public IQueryable Delete(int id)
{
var repository = new ProductRepository();
return repository.Delete(id).AsQueryable();
}
这是对数据库的调用,其中 return 是产品列表。
internal List<Product> Delete(int Id)
{
IDbConnection connection;
using (connection = new SqlConnection(ConfigurationManager.ConnectionStrings["Liberty"].ToString()))
{
var result = connection.QueryMultiple("DeleteProduct", new{prodId = Id}, commandType: CommandType.StoredProcedure);
var products = result.Read<Product>().ToList();
return products;
}
}
我怎么弄错了?
您可以将 DELETE 操作的 return 类型指定为数组,因为这是您的 Web API 控制器 returns:
function productResource($resource) {
return $resource("/api/products/:id", { }, {
'delete': {
method: 'DELETE',
isArray: true
}
});
}