MVC中使用MVCPager简单分页

时间:2022-09-21 12:07:30

一、建立数据库以及建立MVC项目

自己随便建立一个数据库,并且添加数据。我建立的数据库如下。

MVC中使用MVCPager简单分页

二、建立LINQ to SQL映射。

MVC中使用MVCPager简单分页

然后一步步点确定

三、编写代码

在Controllers中建立控制器,模板为空。建立的项目如下:

要添加视图Index

MVC中使用MVCPager简单分页

在Controller中选中Index 并且添加视图, 模板选中List, 如下

MVC中使用MVCPager简单分页

注意后台要添加对MvcPager的程序集引用,后台代码如下:

using Webdiyer.WebControls.Mvc;

 public class StudentController : Controller
{
//
// GET: /Student/ public ActionResult Index(int id=1)
{
Models.StudentEntityDataContext student= new Models.StudentEntityDataContext();
IQueryable<Models.S> p = from c in student.S
select c;
PagedList<Models.S> m = p.ToPagedList(id,10);
return View(m);
}
}

  

前台代码如下:

@model PagedList<MvcApplication1.Models.S>

@{
Layout = null;
}
@using Webdiyer.WebControls.Mvc; //添加对程序集的引用
<!DOCTYPE html> <html>
<head>
<title>Index</title>
// 控制分页的CSS样式
<style type="text/css">
table, td
{
font: 100% Arial, Helvetica, sans-serif;
}
table
{
width: 100%;
border-collapse: collapse;
margin: 1em 0;
}
th, td
{
text-align: left;
padding: .5em;
border: 1px solid #fff;
}
th
{
background: #328aa4;
color: #fff;
}
td
{
background: #e5f1f4;
} /*div布局*/
.div float
{
float: left;
width: 50%;
}
#div pages
{
height: 300px;
}
/*分页工具栏样式*/
.pages
{
color: #045FB4;
font-weight: bold;
font-size: 14px;
} .pages .item
{
padding: 1px 6px;
font-size: 14px;
}
/*号码页数*/ .pages .cpb
{
color: #045FB4;
padding: 1px 6px;
font-size: 13px;
}
/*当前页数*/ .pages a
{
text-decoration: none;
padding: 0 5px;
border: 1px solid #BDBDBD;
margin: 0 2px;
color: #000;
font-weight: normal;
} .pages a:hover
{
background-color: #0174DF;
color: #fff;
border: 1px solid #0174DF;
text-decoration: none;
font-weight: normal;
}
</style>
</head>
<body>
<p>
@Html.ActionLink("Create New", "Create")
</p>
<table>
<tr>
<th>
学号
</th>
<th>
姓名
</th>
<th>
性别
</th>
<th>
准考证
</th>
<th>
专业
</th>
<th>
院系
</th>
<th>
考场
</th>
<th>
座位
</th>
<th>
编排校区
</th>
<th>
语言级别
</th>
<th>
年级
</th>
<th></th>
</tr> @foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.学号)
</td>
<td>
@Html.DisplayFor(modelItem => item.姓名)
</td>
<td>
@Html.DisplayFor(modelItem => item.性别)
</td>
<td>
@Html.DisplayFor(modelItem => item.准考证)
</td>
<td>
@Html.DisplayFor(modelItem => item.专业)
</td>
<td>
@Html.DisplayFor(modelItem => item.院系)
</td>
<td>
@Html.DisplayFor(modelItem => item.考场)
</td>
<td>
@Html.DisplayFor(modelItem => item.座位)
</td>
<td>
@Html.DisplayFor(modelItem => item.编排校区)
</td>
<td>
@Html.DisplayFor(modelItem => item.语言级别)
</td>
<td>
@Html.DisplayFor(modelItem => item.年级)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Details", "Details", new { /* id=item.PrimaryKey */ }) |
@Html.ActionLink("Delete", "Delete", new { /* id=item.PrimaryKey */ })
</td>
</tr>
} </table> //这里是分页的控制
<div>
@Html.AjaxPager(Model, new PagerOptions() { CssClass = "pages", PageIndexParameterName = "id",
ShowPageIndexBox = true, PageIndexBoxType = PageIndexBoxType.TextBox, ShowGoButton = true,
PageIndexBoxWrapperFormatString="转到{0}"}, new AjaxOptions() { UpdateTargetId = "dvOrders" }) </div> </body>
</html>

  四、最终分页效果

MVC中使用MVCPager简单分页

代码下载地址: http://download.csdn.net/detail/luoyangwyb/7581651

MvcPager官方下载网址:http://mvcpager.codeplex.com/releases/view/47201

Demo的示例网址:http://en.webdiyer.com/

MVC中使用MVCPager简单分页的更多相关文章

  1. ASP&period;NET MVC中使用MvcPager异步分页&plus;在分页中复选框下一页上一页也保持选中

    ASP.NET MVC 分页使用的是作者杨涛的MvcPager分页控件  地址:http://www.webdiyer.com/mvcpager/demos/ajaxpaging/ 这个分页控件在里面 ...

  2. FineUIMvc随笔(6)对比WebForms和MVC中表格的数据库分页

    声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 通过对比WebForms和MVC中表格数据库分页代码的不同,可以对 MVC 中的数据流转有更加深入的了解. WebForms 中 ...

  3. asp&period;net mvc 中 一种简单的 URL 重写

    asp.net mvc 中 一种简单的 URL 重写 Intro 在项目中想增加一个公告的功能,但是又不想直接用默认带的那种路由,感觉好low逼,想弄成那种伪静态化的路由 (别问我为什么不直接静态化, ...

  4. MVC001之mvcpager简单分页

    描述:用mvcpager实现简单分页功能 参考网址: http://www.cnblogs.com/iamlilinfeng/archive/2013/03/11/2951460.html http: ...

  5. asp&period;net -mvc框架复习(5)-ASP&period;NET MVC中的视图简单使用

    1.视图分类 ASPX视图(现在讲解) Razor视图(后面讲解) ASPX 视图: 2.@page指令 作用:页面的声明 要求:必须放在第一行,常用指令属性如下: 3.服务器端内嵌语法 小脚本:在A ...

  6. 【MVC】使用MvcPager进行分页

    1.添加引用: mvcPager 版本高的提供的功能也更多. 注:下载了第一个,但是里面的一些字段是只读的.(eg:PagedList<T> .TotalItemCount)这是不符合的. ...

  7. MVC中验证码的简单使用

    首先新建一个MVC项目 添加类:验证码帮助类(ValidateCodeHelper) using System; using System.Collections.Generic; using Sys ...

  8. &period;net mvc中一种简单的工作流的设计

    开篇前的废话:工作流是我们在做互联网应用开发时经常需要用到的一种技术,复杂的工作流我们基本是借助一些开源的 工作流项目来做,比如 ccflow等,但是有时候,我们只需要实现一些简单的工作流流程,这时候 ...

  9. mvc中hangfire全局简单配置

    public void Configuration(IAppBuilder app)       {           ConfigureAuth(app);           //指定使用Sql ...

随机推荐

  1. Laravel 安装代码智能提示扩展「laravel-ide-helper」

    ========================laravel-ide-helper======================== 使用 Laravel 框架IDE居然没有智能提示?这感觉实在太糟糕 ...

  2. penpyxl basic function demo code

    Openpyxl basic function demo code demo code: #!/usr/bin/env python # -*- coding: utf-8 -*- "&qu ...

  3. 关于jquery中html&lpar;&rpar;、text&lpar;&rpar;、val&lpar;&rpar;的区别

    1. .html()用为读取和修改元素的HTML标签    对应js中的innerHTML .html()是用来读取元素的HTML内容(包括其Html标签),.html()方法使用在多个元素上时,只读 ...

  4. myeclipse6&period;0 序列号生成器源码

    import java.io.*; public class Test{ private static final String LL = "Decompiling this copyrig ...

  5. jquery插件,美化select标签

    最近经常与select打交道,因为ie下的select实在太丑了,css怎么搞都搞不好看,因为程序已经写得差不多了,要再去模拟select改动太大,就想着能否不改动select,同时美化它.借鉴一下这 ...

  6. MongoDB高级操作

    参考MongoDB菜鸟教程 一.$type操作符 MongoDB 中可以使用的类型如下表所示: 类型 数字 备注 Double 1   String 2   Object 3   Array 4   ...

  7. 数据帧CRC32校验算法实现

    本文设计思想采用明德扬至简设计法.由于本人项目需要进行光纤数据传输,为了保证通信质量要对数据进行校验.在校验算法中,最简单最成熟的非CRC校验莫属了. 得出一个数的CRC校验码还是比较简单的: 选定一 ...

  8. iOS中 喷枪打字动画的实现

    实现原理比较简单,这里不做过多介绍. #import "ViewController.h" @interface ViewController () @property (weak ...

  9. iOS:检测多媒体&lpar;相机、相册、麦克风&rpar;设备权限,弹框提示

    一.感言 新年伊始,万象更新,一转眼,就2019年了. 作为一个科班生,从事移动端开发好几年了,回顾曾经的摸爬滚打,兢兢业业,严格的来说,多少算是入行了. 过去成绩如何暂且不说,新的一年,我当加倍努力 ...

  10. Flex 程序执行顺序&excl;

    Flex 执行加载过程会有几个概念:preloader, SystemManager, Flex Application! flex 界面初始化时,看到的 Loading 加载条,那是 flex 自动 ...