Is it possible to successfully pass the Id parameter from ActionResult to JsonResult? I am currently experiencing difficulties with passing the Id data to the JsonResult parameter, resulting in an error when trying to execute the following code.
I am utilizing angularjs to showcase a list of tables.
[HttpGet]
public ActionResult ManageCustomerStocks(Int64 Id)
{
return View();
}
public JsonResult GetStocksByCustomerId(Int64 Id)
{
List<CustomerStocksVM> model = new List<CustomerStocksVM>();
var stocks = _repositories.GetStocksByClientProfileId(Id);
var result = from stock in stocks
select new StocksVM()
{
Code = stock.Code,
Name = stock.Name
};
model = result.ToList();
return Json(new
{
customerstocks = model
},JsonRequestBehavior.AllowGet);
}
Javascript:
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', ['$scope', '$http', function ($scope, $http) {
$scope.reverse = true;
$scope.sortBy = function (propertyName) {
$scope.reverse = ($scope.propertyName === propertyName) ? !$scope.reverse : false;
$scope.propertyName = propertyName;
};
$http({
method: 'POST',
url: 'GetStocksByCustomer'
})
.then(function (response) {
console.log(response);
$scope.customerstocks = response.data.customerstocks ;
}, function (error) {
console.log(error);
});
}]);