2016-05-01 6 views
2

ASP 5.0 WebAPIを使用してカスタマーコントローラでページネーションを作成しようとしています。私はこの例をしようとすると私が取得:WebAPI Oneのページネーション(ASP5/vNext)

は、暗黙のうちに、私はちょうどと顧客のコレクションを返す必要が

をAPI.Controllers.IHttpActionResultするタイプのMicrosoft.AspNet.Mvc.HttpOkObjectResult を変換できません。現在のページの数、ページと結果の合計。

public IHttpActionResult Get(int offset = 0, int limit = 50) 
{ 
    // Get total number of records 
    int total = _dbContext.Customers.Count(); 

    // Select the customers based on paging parameters 
    var customers = _dbContext.Customers 
     .OrderBy(c => c.Id) 
     .Skip(offset) 
     .Take(limit) 
     .ToList(); 

    // Return the list of customers 
    return Ok(new 
    { 
     Data = customers, 
     Paging = new 
     { 
      Total = total, 
      Limit = limit, 
      Offset = offset, 
      Returned = customers.Count 
     } 
    }); 
} 
+0

'IHttpActionResult'を' IActionResult'に変更してください – Nkosi

答えて

2

あなたは... IHttpActionResultIActionResult

Controller.Ok()戻りHttpOkObjectResultを変更する必要が

public class HttpOkObjectResult : ObjectResult, IActionResult {...} 

...あなたのメソッドのシグネチャは、以前のバージョンからあるIHttpActionResultを定義しながら、