从WebApi中的发布请求获取数据

时间:2019-04-27 21:36:08

标签: asp.net-web-api

我想在请求请求后获取数据,我在客户端有以下代码:

function (data) {
 console.log((data));
 const requestOptions = {
  headers: { 'Authorization': 'Bearer ' + 
 sessionStorage.getItem("accessToken") } };

 return $http.post("/api/Account/Filter", data, requestOptions);

            }

这是在服务器端:

    public IHttpActionResult Filter(Models.DataSourceRequest request)
    {
        var employees = db.Users.OrderBy(ii => ii.Id).Select(x => new 
     RegisterBindingModel()
        {
            Id = x.Id,
            Email = x.Email,
            UserName = x.UserName,
            FirstName = x.FirstName,
            LastName = x.LastName,
            Age = x.Age,
            Phone = x.Phone,
            Department = x.Department
        });
        var i = employees.ToDataSourceResult(request.Take, request.Skip, request.Sort, request.Filter);
        var data = i.Data; // This is contain filtered data
        request.Take = i.Total;
        System.Diagnostics.Debug.WriteLine(Json(data));
        return Json(i.Data);
    }

如何将数据发送到客户端?

0 个答案:

没有答案