如何使用 apiController 和 angular 删除多个记录?
我试过以下。但我没有成功
api控制器:
public class NewsCategoriesController : ApiController
{
private readonly IJN_NewsCategoriesService _ijnNewsCategoriesService;
public NewsCategoriesController(IJN_NewsCategoriesService ijnNewsCategoriesService)
{
_ijnNewsCategoriesService = ijnNewsCategoriesService;
}
public void Delete(int id)
{
_ijnNewsCategoriesService.DeleteNewsCategory(id);
}
public void ManyDelete(DeleteViewModel ids)
{
var d = ids;
}
}
public class DeleteViewModel
{
public int[] ids { get; set; }
}
}
阿贾克斯方法:
deleteNewsCategories: function (id) {
return $http({
method: 'DELETE',
url: '/api/newsCategories/' + id
});
},
deleteManyNewsCategories: function (ids) {
return $http({
method: 'DELETE',
url: '/api/newsCategories/' + JSON.stringify(ids),
traditional: true
});
}
删除记录正常工作。要删除多条记录,会出现以下错误:
Failed to load resource: the server responded with a status of 400 (Bad Request)
http://localhost:25768/api/newsCategories/[12,26]