简体   繁体   中英

How to declare pagination pagesize in web.config or to my view

I have implemented paging using PageList.MVC. Now I need to that i can change the pagesize from my web.config. Any idea ....

Here is my controller: 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));
    }

And this is my view

           @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> 

            }

I don't think you want this to be controlled from web.config however, you can do this by having a key inside appsettings section in web.config file.

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

And then you can access inside your code as

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

Typically you would want users to control pageSize from the view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM