I am new with angular. I want to get the data from an action name (MVC) using http.
In the console I got a GET line, then the following error occurs : "Possibly unhandled rejection: ": {"data":"\r\n\r\n \r\n "
My code in the html view file :
[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>
My code in the .cs file (action MVC)
[HttpGet]
public ActionResult OPCVMLoad()
{
OPCVM opcvm1 = new OPCVM();
opcvm1.OPCVMcode = 1;
opcvm1.OPCVMname = "Bernardin";
return Json(opcvm1, JsonRequestBehavior.AllowGet);
}