У меня есть эта услуга
this.getyear = function (bookId) {
alert();
var response = $http({
method: "post",
url: "Dashboard/GetyearId",
data: JSON.stringify(12,14),
dataType: "json"
});
return response;
}
это мой контроллер
controller('myController', function ($scope, AttendanceService) {
var getyear = AttendanceService.getyear();
getyear.then(function (_book) {
})
});
и это мой метод actionresult
public ActionResult GetyearId(string Yearid)
{
return Json(Yearid, JsonRequestBehavior.AllowGet);
}
Я хочу передать 2-3 идентификатора в actionresult и вернуть его там. Как это возможно? Я очень новичок в angularJS. Спасибо заранее
Я думаю, что service
может быть примерно такой:
//service
this.getyear = function (bookId) {
return $http({
method: "post",
url: "Dashboard/GetyearId",
data: JSON.stringify([12, 13, 14]) //for three ids
});
}
//and controller:
controller('myController', function ($scope, AttendanceService) {
AttendanceService.getyear()
.then(function (_book) {
})
});
Я предпочитаю звонить так:
this.getyear = function (bookId) {
var url = "Dashboard/GetyearId",
var data = [12,10]; //A json object
//or
var data = JSON.stringify([10,14]) //in your case, but better pass and receive objects
return $http.post(url, data);
}