本文介绍了无法使用参数从AngularJs Controller调用Mvc Controller Action的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从Angularjs控制器$ http.get()调用我的Mvc控制器动作.请提供一些解决方案.
I am trying to call my Mvc Controller Action from Angularjs controller $http.get(). Please provide some solution.
控制器操作:
[HttpGet]
public string CallMe(int number,string name)
{
return "Welcome " + name +" to Angular Js " + number + " times.";
}
Angular JS Controller
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);
});
}]);
还可以请任何人指定相关的学习材料吗?
Also, Could anyone please specify related material for learning?
谢谢.
推荐答案
您正在使用 $ http# get 方法.
get(url, [config]);
Param Type Details
url string Relative or absolute URL specifying the destination of the request
config Object Optional configuration object
(optional)
用于传递参数angular.http
为其提供选项params
For passing parameters angular.http
provides an option for it params
$http({
url: "/Home/CallMe",
method: "GET",
params: {number: 4, name: "angular"}
});
这篇关于无法使用参数从AngularJs Controller调用Mvc Controller Action的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!