简体   繁体   中英

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"?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM