Angular js + Type Script in http put status 400 using DNN7 出错

Getting Error in Angular js + Type Script in http put status 400 using DNN7

我已经使用 angular js 实现了一个控制器,并使用 dot net nuke 键入脚本 7.and 试图使用 http.put 调用我的网络 api 方法,但在状态为 400。 这是我的控制器代码:-

var customerapp = angular.module('CustomerSearch');
module CustomerSearch.controllers
{
    export class CustomerCtrl {
        static $inject = ['$scope', '$http', '$templateCache'];
        debugger;
        constructor(protected $scope: ICustomerScope,
            protected $http: ng.IHttpService,
            protected $templateCache: ng.ITemplateCacheService) {
            $scope.search = this.search;
            console.log(angular.element($scope).scope());
        }
        public search = (search: any) => {
            debugger;
           var Search = {
                ActId: search.txtAct,
                checkActiveOnly: search.checkActiveOnly,
                checkParentsOnly: search.checkParentsOnly,
                listCustomerType: search.listCustomerType
            };

            this.$scope.customer = [];
            this.$scope.ticket = [];
            this.$scope.services = [];


            this.$http.put('<%=ResolveUrl("~/API/Search/PutDoSearch")%>', Search).
                success((data, status, headers, config) => {
                debugger;
                this.$scope.cust_File = data[0].customers;
                this.$scope.ticket_file = data[0].tickets;
                this.$scope.service_file = data[0].services;
            }).
                error((data, status) => {
                debugger;
                console.log("Request Failed");
                alert(status);
                });

        }
    }
    var customerapp = angular.module("CustomerSearch", []);
    customerapp.controller('CustomerCtrl', CustomerSearch.controllers.CustomerCtrl);
}

你应该摆脱

this.$http.put('<%=ResolveUrl("~/API/Search/PutDoSearch")%>', Search)

而是使用:

this.$http.put("/API/Search/PutDoSearch", Search)

您需要让服务器为您解析 <%=ResolveUrl("~/API/Search/PutDoSearch")%>

您可以通过一种方式执行此操作,例如放入脚本标记

<script>
       var doSearchUrl = '<%=ResolveUrl("~/API/Search/PutDoSearch")%>';
</script>

然后在你的打字稿中有

// At the root of your file
declare var doSearchUrl:string; 

// And later
this.$http.put(doSearchUrl, Search)