【发布时间】:2016-09-20 14:54:05
【问题描述】:
我是 Angular 新手,想知道如何发布数据。
我有一个用 Angular 制作的控制器:
myApp.factory('employeeServices', ['$http', function ($http) {
var factoryDefinitions = {
moveToBench: function (employeeId) {
var data = $.param({
json: JSON.stringify({
"entityId": employeeId,
"nextStateId": myApp.state.bench
})
});
return $http.post(myApp.IndecommBaseUrl + '/Workflow',data).success(function (data) {
return data;
});
}
}
return factoryDefinitions;
}
]);
//Controller
myApp.controller('getEmployeesController', ['$scope', 'employeeServices', 'dataTable', function ($scope, employeeServices, dataTable) {
employeeServices.getEmployees().then(function (result) {
$scope.moveToBench = function (id) {
employeeServices.moveToBench(id);
}
});
}]);
我有一个 HTML 按钮:
<button class="btn btn-success" ng-click="moveToBench(employee.employee.id)">Move To Bench</button>
按下按钮时,我可以看到:
moveToBench: function (employeeId) {
var data = $.param({
json: JSON.stringify({
"entityId": employeeId,
"nextStateId": myApp.state.bench
})
是正确的。但是当它到达 API 时,它的值为 NULL..
后端 API 控制器是:
// POST api/values
[HttpPost]
public void Post(int entityId, int nextStateId)
{
JObject jsonObject = JObject.Parse(System.IO.File.ReadAllText("Config.Json"));
string jsonFile = jsonObject.GetValue("WorkfowJsonFileLocation").ToString();
var nextState = _stateServices.Get(nextStateId);
var handler = new WorkflowHandler(nextState, jsonFile, _entityServices, 1, _stateServices, _subStateServices, _appServices);
handler.PerformAction(entityId);
}
谁能帮我解决这个问题?
【问题讨论】:
标签: angularjs post asp.net-core