1. 程式人生 > 實用技巧 >筆試考試系統 ____pagelist使用

筆試考試系統 ____pagelist使用

1.今日任務

PageList分頁使用

2.使用方式及原始碼

(1) 新增nuget程式包

控制器程式碼:

 1 using PagedList;
 2 using System;
 3 using System.Collections.Generic;
 4 using System.Linq;
 5 using System.Web;
 6 using System.Web.Mvc;
 7 
 8 namespace WebApplication2.Controllers
 9 {
10     public class DefaultController : Controller
11
{ 12 // GET: Default 13 public ActionResult Index(int pagenumber=1,int pazesize=2) 14 { 15 Models.ExamSysEntities DB = new Models.ExamSysEntities(); 16 17 var data = DB.Exam_User.ToList().ToPagedList(pagenumber, pazesize); 18 19 return
View(data); 20 } 21 } 22 }

頁面

 1 @using PagedList
 2 @using PagedList.Mvc
 3 @using Exam.Model 
 4 @model IPagedList<Exam_PaperRule>
 5 
 6 @{
 7     Layout = "~/Views/Shared/_Layout.cshtml";
 8 }
 9 
10 <div class="larry-fluid larry-wrapper fadeInRightBig">
11     <div class
="layui-row lay-col-space15 "> 12 <table class="layui-table" lay-skin="line"> 13 14 <colgroup> 15 <col> 16 <col width="100"> 17 <col width="120"> 18 <col width="150"> 19 </colgroup> 20 <thead> 21 <tr> 22 <th>試卷編號</th> 23 <th>試卷名稱</th> 24 <th>考試開始時間</th> 25 <th>考試結束時間</th> 26 <th>試卷總分</th> 27 <th>題目數量</th> 28 <th>成績統計</th> 29 30 </tr> 31 </thead> 32 <tbody> 33 @foreach (var item in Model) 34 { 35 <tr> 36 <td>@item.PaperRuleID</td> 37 <td>@item.RuleName</td> 38 <td>@item.RuleStartDate</td> 39 <td>@item.RuleEndDate</td> 40 <td>@item.Score</td> 41 <td>@item.QuestionNum</td> 42 <td> 43 <a onclick="return check_href('/ExamMannage/[email protected]')" class="larry-add-edit ajax-get layui-btn layui-btn-small layui-btn-normal larry-add-edit"> 44 <i class="larry-icon larry-bianji4"></i>成績統計 45 </a> 46 </td> 47 @*<td> 48 <a onclick="return check_href('/Exam/[email protected]')" class="larry-add-edit ajax-get layui-btn layui-btn-small layui-btn-normal larry-add-edit"> 49 <i class="larry-icon larry-bianji4"></i>錯題統計 50 </a> 51 </td>*@ 52 </tr> 53 } 54 </tbody> 55 <tfoot> 56 @if (Model != null && Model.Any() && Model.Count > 1) 57 { 58 <tr> 59 <td colspan="4" align="center"> 60 <div style="float:left;width:370px;font-size:12px;height:34px;line-height:34px;"> 61 每頁 @Model.PageSize 條記錄,共有 @Model.TotalItemCount 條記錄。 62 第 @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) 頁,共 @Model.PageCount 頁。 63 <input type="hidden" name="page" value="1" /> 64 <input id="last" type="hidden" name="page" value="@Model.PageCount" /> 65 </div> 66 67 @Html.PagedListPager(Model, page => Url.Action("Index", new 68 { 69 page, 70 lmid = ViewBag.Lmid 71 }), new PagedListRenderOptions() 72 { 73 LinkToFirstPageFormat = "首頁", 74 LinkToNextPageFormat = "下一頁", 75 LinkToPreviousPageFormat = "上一頁", 76 LinkToLastPageFormat = "末頁", 77 DisplayItemSliceAndTotal = false, 78 //頁面最多顯示的頁碼數 79 MaximumPageNumbersToDisplay = 5 80 }) 81 </td> 82 </tr> 83 } 84 </tfoot> 85 </table> 86 </div> 87 </div>

效果:

對應的分頁的樣式自己可以寫css進行調整

3.遇到問題

分頁沒有對應的樣式

4.手寫css進行設定(由於這個框架是隻是後臺的類庫沒有對應的css庫,樣式需要自己濟寧設定)