【问题标题】:How to declare pagination pagesize in web.config or to my view如何在 web.config 或我的视图中声明分页页面大小
【发布时间】:2014-06-20 14:41:34
【问题描述】:

我已经使用 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 paging pagedlist web-config


    【解决方案1】:

    我认为您不希望通过 web.config 进行控制,但是您可以通过在 web.config 文件的 appsettings 部分中设置一个密钥来实现。

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

    然后你可以在你的代码中访问

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

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

    【讨论】:

    • 谢谢我以同样的方式做到了......但我为pagesize创建了一个单独的类。
    猜你喜欢
    • 1970-01-01
    • 2013-12-14
    • 1970-01-01
    • 2016-06-29
    • 1970-01-01
    • 2013-09-16
    • 1970-01-01
    • 2015-12-21
    • 2016-03-09
    相关资源
    最近更新 更多