如何从ActionResult向JsonResult传递Id参数(我已经传入了Id参数)?因为现在我不能将Id数据传递给JsonResult参数,所以它不能命中下面的JsonResult代码。
我使用angularjs来显示表格的列表。
[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);
});
}]);发布于 2017-06-06 17:26:08
$http({
url: 'request-url',
method: "POST",
data: { 'id' : urId }
})
.then(function(response) {
// success
},
function(response) { // optional
// failed
});发布于 2017-06-07 20:48:42
如果您想从后端获取一些东西,请使用http.get:
javascript:
function GetStocksByCustomerId(id) {
return $http.get("GetStocksByCustomer", { params: { "id":
id} })
.then(function (response) {
return response.data
})
.catch();
}在angular服务中设置http调用
https://stackoverflow.com/questions/44385704
复制相似问题