我是一名新手,正在学习Angular。
我想使用http获取来自一个动作名称(MVC)的数据。
在控制台中,我得到了一个GET行,然后出现了以下错误:
"Possibly unhandled rejection: ": {"data":"\r\n\r\n \r\n "
我的html视图文件中的代码:
[HttpGet]
public ActionResult OPCVMLoad()
{
OPCVM opcvm1 = new OPCVM();
opcvm1.OPCVMcode = 1;
opcvm1.OPCVMname = "Bernardin";
return Json(opcvm1, JsonRequestBehavior.AllowGet);
}
<script>
var myApp = angular.module("myApp", []);
myApp.controller('OPCVMViewModel', ['$scope', '$http', function ($scope, $http) {
$scope.OPCVM = {
"OPCVMcode": "",
"OPCVMname": ""
};
$scope.OPCVMs = {};
$scope.TestClick = function TestClick() {
alert("test clic");
};
$scope.GetAllData = function GetAllData() {
alert("break point in function GetAllData");
$http.get("GrilleFast/OPCVMLoad")
.then(function (response)
{
$scope.OPCVM = response.data;
})
};
}]);
</script>
<div ng-controller="OPCVMViewModel">
<input name="BtnAddNew" type="button" value="Load all OPCVM" ng-click="GetAllData()" />
{{OPCVM.OPCVMcode}} <br />
{{OPCVM.OPCVMname}}
</div>
我的代码在.cs文件中(MVC操作)
[HttpGet]
public ActionResult OPCVMLoad()
{
OPCVM opcvm1 = new OPCVM();
opcvm1.OPCVMcode = 1;
opcvm1.OPCVMname = "Bernardin";
return Json(opcvm1, JsonRequestBehavior.AllowGet);
}
angularjs
。angular
保留用于Angular 2+版本。 - borislemke