Ajax 使用ApicController和angular删除多条记录
如何使用ApicController和angular删除多条记录 我试过以下方法。但我没有成功 api控制器:Ajax 使用ApicController和angular删除多条记录,ajax,angularjs,asp.net-mvc-apiexplorer,Ajax,Angularjs,Asp.net Mvc Apiexplorer,如何使用ApicController和angular删除多条记录 我试过以下方法。但我没有成功 api控制器: public class NewsCategoriesController : ApiController { private readonly IJN_NewsCategoriesService _ijnNewsCategoriesService; public NewsCategoriesController(IJN_NewsCatego
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; }
}
}
ajax方法:
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]
问题解决了
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 }
});
}
也许这就是你的解决方案:谢谢。但是这个问题并没有用这个解决方案解决。其他HTTP方法得到了吗,POST工作正常吗?在我看来,您在两个实例中对一个只接受整数的DELETE函数进行了相同的调用。我不知道ApiController是如何工作的,我自己也没用过,但似乎你的ManyDelete永远也没有达到。