Kamran G.
Kamran G.

Reputation: 463

Cant pass data from angular to Mvc controller

Its is my Angular controller

 var app=angular.module('app',[]);

 app.controller('myCtrl', function ($scope,$http) {


console.log($scope.add)

 $scope.asd = function (data)
{
     $http({
         url: '/Home/My',
         method: "GET",
         data: data
     });
}

//console.log($scope.asd);
});

When im passing data like this it is working well

 {
     $http({
         url: '/Home/My',
         method: "GET",
          params: { data: data}
     });
}

Mvc controller

      public ActionResult My(List<string> data)
      {

        return View();
      }

But why couldnt i pass it with "data"?

Upvotes: 0

Views: 916

Answers (1)

Robert Columbia
Robert Columbia

Reputation: 6408

Looking at the Angular documentation at https://docs.angularjs.org/api/ng/service/$http , it seems that the "params" parameter refers to data that you want to pass as HTTP GET parameters, while the "data" parameter simply dumps the content into the HTTP request.

Is there a specific reason why you want it to work the first way? If there is not, then the second way appears to be the more elegant choice as it strengthens the interface contract between your Angular and MVC components.

Upvotes: 1

Related Questions