[英]Passing array of int to Api Controller using $http in Javascript
我可以在这个问题上得到一些帮助吗?
I'm trying to send an array of int from my javascript function to my api controller but can't get the correct configuration for the controller - the projectsId passed into the controller is always null.
Javascript function:
getProducts: function (projects) {
return $http({
method: 'POST',
url: '/api/settings/products',
data: projects
}).then(function (result) {
return result.data;
}, function (result) {
return result;
});
传递给 getProducts 的项目是一个 int 数组。
Controller:
[HttpPost]
[Route("products")]
public IHttpActionResult Export([FromBody] int[] projectIds)
{
var exportProducts = new List<Product>();
谢谢你。
在您调用getProducts
的地方,输入参数应类似于:
var products = [1, 2, 3];
为了帮助调试,请将console.log(projects)
添加到您的getProducts
function。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.