ASP.NET MVC獲取微信返回的json數據分頁

View算法

@model JiaYe.WeiXin.Models.ViewModels.UserViewModel
<div class="pull-left pagination">
    <ul class="pagination pagination-outline">
    @{
       //分頁算法:(總記錄數+每頁記錄數-1)/每頁記錄數 var totalPageNum = (Model.OpenIdResult.openid.Count + 10 - 1)/10; for (int id = 1; id
<= totalPageNum; id++) { <li class="page-number"> <a href="/User/Index/@id">@id</a> </li> } } </ul> </div>

Controllerspa

public ActionResult Index(int id = 1)
        {
            var userresult = UserApi.Get(GetAccessToken(), "");
            int pagesize = id*10;
            List<BatchGetUserInfoData> userList = new List<BatchGetUserInfoData>();
       //每十個數據爲一頁
for (int i = pagesize - 10;i < ((pagesize - userresult.data.openid.Count < 0) ? pagesize : userresult.data.openid.Count);i++) { BatchGetUserInfoData user = new BatchGetUserInfoData(); user.openid = userresult.data.openid[i]; userList.Add(user); } UserViewModel userViewModel = new UserViewModel(); userViewModel.OpenIdResult = userresult.data; userViewModel.BatchGetUserInfoResult = UserApi.BatchGetUserInfo(GetAccessToken(), userList); return View(userViewModel); }
相關文章
相關標籤/搜索