如何在 web.config 或我的视图中声明分页页面大小

问题描述 投票:0回答:1

我已经使用PageList.MVC实现了分页。现在我需要可以从 web.config 更改页面大小。任何想法....

这是我的控制器: 公共 ActionResult UsersWhoHaveConsumedFreeCredit(int Id = 1) {

        var result = Manager.GetUsersWhoHaveConsumedFreeCredit();
        JavaScriptSerializer serializer = new JavaScriptSerializer();
        var model = serializer.Deserialize<List<CallHistory>>(result);
        int pageSize = 100;
        //int pageNumber = (page ?? 1);


        return View(model.ToPagedList(Id, pageSize));
    }

这就是我的观点

           @model PagedList.IPagedList<MyYello.Admin.Models.CallHistory>

   @{
      ViewBag.Title = "UsersWhoHaveConsumedFreeCredit";
     Layout = "~/Views/Shared/_Layout.cshtml";
    }

    <h2>Users Who Have Consumed Free Credit</h2>
     @*<table class="table table-striped table-bordered tablesorter" style="display: block">
  <thead>

    <tr>
        <th>Login</th>
        <th>FirstName</th>
        <th>LastName</th>
        <th>Email</th>
        <th>Country</th>
        <th>TarrifDesc</th>
        <th>CalledNum</th>
        <th>CallStart</th>
        <th>CallEnd</th>
  </tr>
    </thead>*@
    @foreach (var group in Model.GroupBy(dialed => dialed.Login))
    {
        var item = group.First();
    {
        <table>
            <tbody>
                <th class="custom-padding">Login Id</th>
                <th class="custom-padding">Phone</th>
                <th class="custom-padding">First Name</th>
                <th class="custom-padding">Last Name</th>
                <th class="custom-padding">Email</th>
                <th class="custom-padding">Country</th>
        <tr>

            <td class="custom-padding">@item.Login </td>
            <td class="custom-padding">@item.Phone</td>
            <td class="custom-padding">@item.FirstName</td>
            <td class="custom-padding">@item.LastName</td>                
            <td class="custom-padding">@item.Email</td>
            <td class="custom-padding">@item.Country</td>
            <th class="custom-padding">Dialed Calls:-</th>
            <td class="custom-padding">@string.Join(" - ", group.Select(dialed => dialed.DialedNumber))</td> </tr>
            @*<td>@item.FirstName</td>
            <td>@item.LastName</td>
            <td>@item.Email</td>
            <td>@item.Country</td>*@

            @*<td>@string.Join(" - ", group.Select(history => history.Phone))</td>*@
           <tr> @*<td>@item.TariffDescription</td>*@    
        </tr>
           </tbody>
        </table>  
        <hr /> 
    }
    }


         @* @Html.PagedListPager( (IPagedList)ViewBag.pageNumber, page => Url.Action ("UsersWhoHaveConsumedFreeCredit", new {page}));*@
       <div class="paged-list">
      @Html.PagedListPager(Model, Id => Url.Action("UsersWhoHaveConsumedFreeCredit", new { Id        }), PagedListRenderOptions.Classic)
</div>


        @if (!Model.Any())
            {

                   <h2>No Record Found</h2> 

            }
html asp.net-mvc-4 pagination web-config pagedlist
1个回答
0
投票

我认为您不希望从 web.config 控制它,但是,您可以通过在 web.config 文件的 appsettings 部分中使用密钥来实现此目的。

<appSettings>
   <key name="pageSize" value="10"/>
</appSettings>

然后您可以在代码中访问

int pageSize = Convert.ToInt32(ConfigurationManager.AppSettings["pageSize"])

通常您希望用户从视图控制 pageSize。

© www.soinside.com 2019 - 2024. All rights reserved.