1 Home 代码如下
public class HomeController : Controller { // // GET: /Home/ Model1Container db = new Model1Container(); public ActionResult Index(int pageIndex = 1) { var model = db.Student.OrderBy(p => p.Id).ToPagedList(pageIndex, 3); return View("Index", model); } public ActionResult ProdectList() { return PartialView("_ProdectList"); } }
2.Index 代码如下
@{ ViewBag.Title = "Index"; } @using Webdiyer.WebControls.Mvc @Html.Partial("_ProdectList", Model) @model Webdiyer.WebControls.Mvc.PagedList<MvcApplication1.Student> @Html.Pager(Model, new PagerOptions() { }) @Model.TotalItemCount 篇留言 @Model.CurrentPageIndex/@Model.TotalPageCount
3.部分视图代码如下
@model Webdiyer.WebControls.Mvc.PagedList<MvcApplication1.Student> <table> @foreach (var item in Model) { <tr> <td> @Html.DisplayFor(modelItem => item.Id) </td> <td> @Html.DisplayFor(modelItem => item.Name) </td> <td> @Html.DisplayFor(modelItem => item.Sex) </td> </tr> } </table>
4.运行结果如下