无法使用参数从AngularJs Controller调用Mvc Controller Action

Aja*_*rma 9 c# asp.net-mvc angularjs

我试图从Angularjs controller $ http.get()调用我的Mvc Controller Action.请提供一些解决方案.

控制器动作:

 [HttpGet]
 public string CallMe(int number,string name)
 {
     return "Welcome " + name +" to Angular Js " + number + " times.";
 }
Run Code Online (Sandbox Code Playgroud)

Angular JS控制器

 app.controller("StoreController", ["$http", function ($http) {        
    $http.get("/Home/CallMe", { number: 4, name: "angular"     }).success(function (data) {
        console.log(data);
    }).error(function (error) {           
        console.log(error);
    });
}]);
Run Code Online (Sandbox Code Playgroud)

另外,有人可以指定相关的学习材料吗?

提前致谢.

Ani*_*rni 13

您正在使用$ http#get方法.

get(url, [config]);
Run Code Online (Sandbox Code Playgroud)
 Param    Type     Details
 url      string   Relative or absolute URL specifying the destination of the request

 config   Object   Optional configuration object
(optional)
Run Code Online (Sandbox Code Playgroud)

对于传递参数angular.http,它提供了一个选项params

$http({
   url: "/Home/CallMe", 
   method: "GET",
   params: {number: 4, name: "angular"}
});
Run Code Online (Sandbox Code Playgroud)