gpt4 book ai didi

javascript - 如何将参数从 ActionResult 传递到 JsonResult?

转载 作者:行者123 更新时间:2023-12-03 04:09:33 25 4
gpt4 key购买 nike

如何将Id参数(我已经传入Id参数)从ActionResult传递到JsonResult?因为现在我无法将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);
});
}]);

最佳答案

 $http({
url: 'request-url',
method: "POST",
data: { 'id' : urId }
})
.then(function(response) {
// success
},
function(response) { // optional
// failed
});

关于javascript - 如何将参数从 ActionResult 传递到 JsonResult?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44385704/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com