我遇到与listed here完全相同的问题,但是,列出的解决方案并不起作用。
Angular $资源工厂
.factory("assignMeterToUser", [
"$resource",
"appSettings",
function ($resource, appSettings) {
return {
setAssignedMeters: $resource(
appSettings.serverPath + "/api/assign/saveassigned/",
null, {
"update": { method: "POST" }
})
};
}
])

控制器
(function() {
"use strict";
angular
.module("controller.assignMtrUser", ["ngAnimate", "ngMessages", "ngSanitize", "kendo.directives", "toastr"])
.controller("ctrlAssignMtrUser",
[
"$scope",
"$window",
"appSettings",
"assignMeterToUser",
"toastr",
function ($scope, $window, appSettings, assignMeterToUser, toastr) {
var camu = this;
camu.arrayAdd = [];
camu.jsonIdList = null;
camu.addMtr = function () {
camu.jsonIdList = angular.toJson(camu.arrayAdd);
assignMeterToUser.setAssignedMeters.update(
{ IdList: camu.jsonIdList },
function (data) {
toastr.success("Meters assigned!");
},
function (response) {
camu.errorToast(response);
});
};
]);
}());

包含接受数组的变量的对象:
public class AssignMeterId
{
private List<string> IdList { get; set; }
}
&#13;
Web API控制器:
[AcceptVerbs("POST")]
[Route("saveassigned")]
public Task<IHttpActionResult> SaveAssignedMeters(AssignMeterId assId)
{
IHttpActionResult result;
try
{
_maMgr.SetAssignedMeters(assId);
result = Ok();
}
catch (Exception ex)
{
result = InternalServerError(ex);
}
return Task.FromResult(result);
}
&#13;
有一个:
[RoutePrefix("api/assign")]
&#13;
在该控制器的顶部。我做错了什么?