接下来讲讲PagedList套件的使用方式
在前面有提到Entity Framework 使用的方式 这边以Day20资料库为例这次使用Order作为范例
1.首先先去工具->NuGet套件管理员->管理方案NuGet套件->安装PagedList.Mvc
2.新增一个PagedListController 并加入相关程序码
using PagedList;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication1.Models;
namespace WebApplication1.Controllers
{
public class PagedListController : Controller
{
// GET: PagedList
private DBContext _db = new DBContext();
protected override void Dispose(bool disposing)
{
if (disposing)
{
_db.Dispose();
}
base.Dispose(disposing);
}
public ActionResult Index(int page = 1, int pageSize = 15)
{
var ListAll = from m in _db.Orders
select m;
var pagelist= ListAll.ToList().ToPagedList(page, pageSize);
return View(pagelist);
}
}
}
1.db 为连线资料库
2.page 为第几页
3.pageSize 显示几笔资料
4.最上方需加入using PagedList
3.View的部分
@model IEnumerable<WebApplication1.Models.Order>
@using PagedList.Mvc;
@using PagedList;
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.CustomerID)
</th>
<th>
@Html.DisplayNameFor(model => model.EmployeeID)
</th>
<th>
@Html.DisplayNameFor(model => model.OrderDate)
</th>
<th>
@Html.DisplayNameFor(model => model.RequiredDate)
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.CustomerID)
</td>
<td>
@Html.DisplayFor(modelItem => item.EmployeeID)
</td>
<td>
@Html.DisplayFor(modelItem => item.OrderDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.RequiredDate)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.OrderID }) |
@Html.ActionLink("Details", "Details", new { id = item.OrderID }) |
@Html.ActionLink("Delete", "Delete", new { id = item.OrderID })
</td>
</tr>
}
</table>
@Html.PagedListPager((IPagedList)Model, x => Url.Action("Index", new { page = x }))
1.上方需加入@using PagedList.Mvc、@using PagedList
2.最下方需加入@Html.PagedListPager
4.结果
>>: [Python 爬虫这样学,一定是大拇指拉!] DAY16 - 从爬虫看 API / CGI
第2个决定 决定ERP主要编写程序语言 理论上所有程序语言只要能读取资料库的都可拿来设计一套ERP软...
@csrf_exempt def callback(request): if request.met...
float称为浮动元素,可以想像是加上这个元素的物体都会飘浮在空中 接下来示范一些用法来认识这个元素...
前言 今天就是铁人赛的最後一篇文章了,不免俗的要来写个总结来混一下篇幅XD,也希望这次的铁人赛可以让...
不管是数据分析的过程还是分析结果的呈现,都推脱离不了「数据可视化」,将数据用图表呈现。然而我们该用哪...