从js获取值时web api控制器中的错误

时间:2016-08-30 14:37:38

标签: angularjs asp.net-web-api

我是angularjs的新手,我有一个项目,其中一些get和post方法 这是我的js

var app = angular.module('angularTable', []);

app.controller('listdata', function ($scope, $http) {



$scope.joblist = function (Data) {


    $scope.job = [];

    $.ajax({
        url: "/JobApi/getjoblist",
        dataType: 'jsonp',
        method: 'GET',
        data: Data,
        headers: {
            "Content-Type": "application/json"
        }
    }).success(function (response) {

        $scope.$apply(function () {
            debugger;
            if (response != null) {
                $scope.divstateList = false;
                $scope.divjobList = true;
                $scope.job = response;
            }
        });

    })


.error(function (error) {
  alert(error);


});
}

});

这是我的web api控制器

[System.Web.Http.Route("JobApi/getjoblist")]
    [System.Web.Mvc.HttpPost]

    public List<Getjoblist> getjoblist([FromBody]string Data)
    {
        try
        {
            JobBL objbl = new JobBL();
            var joblist = objbl.Citywisejoblist(Convert.ToInt32(Data));
            List<Getjoblist> list = new List<Getjoblist>();
            foreach (var t in joblist)
            {
                Getjoblist GetAll = new Getjoblist();
                GetAll.jobID = Convert.ToInt32(t.ID);
                GetAll.jobtital = t.Title;
                GetAll.jobdescription = t.Description;
                GetAll.jobimage = t.JobImage;
                list.Add(GetAll);

            }
            return list;
        }
        catch (Exception ex)
        {
            throw ex;
        }


    }

没有从js获取控制器发送的值如何解决问题请帮帮我

0 个答案:

没有答案