2013-12-24 2 views
0

Я показываю ссылки на страницы с помощью PagedList в ASP.net MVC. Но проблема в том, что есть 100 страниц, тогда все ссылки показывают одновременно, но я хочу показывать по 10 ссылок за раз. Как это можно достичь. Пожалуйста помоги. Спасибо. Ниже приведен рабочий код.Показать ограниченное количество страниц за раз в ASP.net MVC

Index.cshtml

@model PagedList.IPagedList<MvcPagingList.Models.Employee> 
@{ 
    ViewBag.Title = "Employees"; 
} 
<link href="@Url.Content("~/bootstrap/css/bootstrap.min.css")" rel="stylesheet" type="text/css" /> 
<link href="@Url.Content("~/bootstrap/css/bootstrap.css")" rel="stylesheet" type="text/css" /> 
<h2> 
    Index</h2> 
<p> 
    @Html.ActionLink("Create New", "Create") 
</p> 
@using (Html.BeginForm()) 
{ 
    <p> 
     Search By Name : @Html.TextBox("SearchString", ViewBag.CurrentFilter as string) 
     &nbsp; 
     <input type="submit" value="Search" /></p> 
} 
<table> 
    <tr> 
     <th> 
      @Html.Label("Last Name") 
     </th> 
     <th> 
      @Html.Label("First Name") 
     </th> 
     <th> 
      @Html.Label("Department ID") 
     </th> 
     <th> 
      @Html.ActionLink("Salery", "Index", new { sortOrder = ViewBag.NameSortParm, currentFilter = ViewBag.CurrentFilter }) 
     </th> 
     <th> 
     </th> 
    </tr> 
    @foreach (var item in Model) 
    { 
     <tr> 
      <td> 
       @Html.DisplayFor(modelItem => item.LastName) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.FirstName) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.DepartmentID) 
      </td> 
      <td> 
       @Html.DisplayFor(modelItem => item.Salary) 
      </td> 
      <td> 
       @Html.ActionLink("Edit", "Edit", new { id = item.EmployeeID }) | 
       @Html.ActionLink("Details", "Details", new { id = item.EmployeeID }) | 
       @Html.ActionLink("Delete", "Delete", new { id = item.EmployeeID }) 
      </td> 
     </tr> 
    } 
</table> 

<div class="pagination pagination-right"> 
    <ul> 
    <li> 
     @for (int p = 1; p <= Model.PageCount; p++) 
     { 
      <a href="@Url.Action("Index", "Home", new { page = p })">@p</a> 
     } 
     </li> 
     </ul> 
    </div> 

HomeController.cs

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.Mvc; 
using MvcPagingList.Models; 
using PagedList; 

namespace MvcPagingList.Controllers 
{ 
    public class HomeController : Controller 
    { 

     EmployeeEntities dbEntities = new EmployeeEntities(); 

     public ViewResult Index(string sortOrder, string currentFilter, string searchString, int? page) 
     { 
      ViewBag.CurrentSort = sortOrder; 
      ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "Salery desc" : ""; 
      //ViewBag.DateSortParm = sortOrder == "HireDate" ? "HireDate desc" : "HireDate"; 

      if (Request.HttpMethod == "GET") 
      { 
       searchString = currentFilter; 
      } 
      else 
      { 
       page = 1; 
      } 
      ViewBag.CurrentFilter = searchString; 

      var employees = from s in dbEntities.Employees 
          select s; 
      if (!String.IsNullOrEmpty(searchString)) 
      { 
       employees = employees.Where(s => s.LastName.ToUpper().Contains(searchString.ToUpper()) 
             || s.FirstName.ToUpper().Contains(searchString.ToUpper())); 
      } 
      switch (sortOrder) 
      { 
       case "Salery desc": 
        employees = employees.OrderByDescending(s => s.LastName); 
        break; 
       default: 
        employees = employees.OrderBy(s => s.LastName); 
        break; 
      } 

      int pageSize = 3; 
      int pageNumber = (page ?? 1); 
      return View(employees.ToPagedList(pageNumber, pageSize)); 
     } 


    } 
} 

ответ

0

Я сталкивался с такой же вопрос & решить ее, изучая следующий код: -

http://msdn.microsoft.com/en-us/magazine/gg650669.aspx

Вы будете для этого нужно использовать webgrid.

http://www.w3schools.com/aspnet/showfile_c.asp?filename=try_webpages_cs_004

+0

Я показываю эту страницу мудрым. т. е. 10 записей за раз, но я хочу показывать ограниченное количество ссылок на страницы за раз ... спасибо за вашу ссылку выше – user3026519

Смежные вопросы