带有ASP.Net Web API参数的Angular POST导致控制器变量

时间:2016-10-06 20:27:21

标签: angularjs post asp.net-web-api

我遇到与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;
&#13;
&#13;

Web API控制器:

&#13;
&#13;
        [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;
&#13;
&#13;

有一个:

&#13;
&#13;
    [RoutePrefix("api/assign")]
&#13;
&#13;
&#13;

在该控制器的顶部。我做错了什么?

0 个答案:

没有答案