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

时间:2014-06-20 14:41:34

标签: html asp.net-mvc-4 paging pagedlist web-config

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

这是我的控制器:                public 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> 

            }

1 个答案:

答案 0 :(得分:0)

我不认为您希望通过web.config控制此操作。但是,您可以通过在web.config文件中的appsettings部分内部设置密钥来实现此目的。

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

然后您可以在代码中访问

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

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