2016-04-24 75 views
0

我试图删除对象,并返回其不触发网页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(); 

    } 

这是CA将返回到产品列表的数据库。

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; 
     } 
    } 

我该如何解决这个错误的方法?

回答

1

您可以指定DELETE操作的返回类型为数组,因为这是你的Web API控制器返回:

function productResource($resource) { 
    return $resource("/api/products/:id", { }, { 
     'delete': { 
      method: 'DELETE', 
      isArray: true 
     } 
    }); 
}