0

如何使用 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]
4

1 回答 1

0

问题解决了。

 public void Delete(int id)
    {
       _ijnNewsCategoriesService.DeleteNewsCategory(id);
    }
    public void DeleteModels(DeleteViewModel dvm)
    {
        var d = dvm;
    }


      public class DeleteViewModel
        {
            public int[] Ids { get; set; }
        }

$http删除方法:

             deleteNewsCategories: function (id) {
                return $http({
                    method: 'DELETE',
                    url: '/api/newsCategories/' + id
                });
            },

            deleteManyNewsCategories: function (ids) {
                return $http({
                    headers: {
                        'Content-type': 'application/json'
                    },
                    method: "DELETE",
                    url: "/api/newsCategories/",
                    data: { Ids: ids }
                });
            }
于 2014-08-07T18:36:33.703 回答