问题/答案你有没有考虑PagedList库分页的?所有你要做的就是引用ASP.NET MVC应用程序中的PagedList库
要安装PagedList.Mvc,请在程序包管理器控制台中运行以下命令。你也可以使用NuGet来获取这个包。
PM> Install-Package PagedList.Mvc
您的视图模型
public class QuestionViewModel
{
public int QuestionId { get; set; }
public string QuestionName { get; set; }
}
在你的控制器,参考PagedList
using PagedList;
and the Index method of your controller will be something like
public ActionResult Index(int? page)
{
var questions = new[] {
new QuestionViewModel { QuestionId = 1, QuestionName = "Question 1" },
new QuestionViewModel { QuestionId = 1, QuestionName = "Question 2" },
new QuestionViewModel { QuestionId = 1, QuestionName = "Question 3" },
new QuestionViewModel { QuestionId = 1, QuestionName = "Question 4" }
};
int pageSize = 3;
int pageNumber = (page ?? 1);
return View(questions.ToPagedList(pageNumber, pageSize));
}
而且你的索引视图
@model PagedList.IPagedList<ViewModel.QuestionViewModel>
@using PagedList.Mvc;
<link href="/Content/PagedList.css" rel="stylesheet" type="text/css" />
<table>
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.QuestionId)
</td>
<td>
@Html.DisplayFor(modelItem => item.QuestionName)
</td>
</tr>
}
</table>
<br />
Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index", new { page }))
而且所得到的屏幕看起来像

你能发布你的代码吗? – Gjohn 2014-10-01 20:36:30
我还没有完成编码。我在找样品。 – 2014-10-01 21:25:08