0

I have this service

  this.getyear = function (bookId) {
            alert();
            var response = $http({
                method: "post",
                url: "Dashboard/GetyearId",
                data: JSON.stringify(12,14),
                dataType: "json"
            });
            return response;
        }

this is my controller

controller('myController', function ($scope, AttendanceService) {
  var getyear = AttendanceService.getyear();
            getyear.then(function (_book) {

            })
});

and this is my actionresult method

 public ActionResult GetyearId(string Yearid)
    {
        return Json(Yearid, JsonRequestBehavior.AllowGet);
    }

I want to pass 2-3 ids to actionresult and retrive it over there.How can it be possible? I am very new to angularJS .Thanks in advance

2 Answers 2

1

I think the service could be something like:

//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) {

        })
});
Sign up to request clarification or add additional context in comments.

5 Comments

But then how to retrieve it on server side actionresult method??
I am getting string Yearid value null on server side
@akash Sorry I'm not so familiar with asp.net, I use php as the server-side language
@akash I've done some other research, please have a look at this link victorblog.com/2012/12/20/…, I used to have similar issue on php, but I'm not sure if that could happen to asp.net
@akash and I also found another post on stackoverflow stackoverflow.com/questions/19254029/…, this guy have similar issue as you have with asp.net, hope this can help :)
0

I prefer calling like this -

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);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.