MVC中使用MVCPager简单分页
一、建立数据库以及建立MVC项目
自己随便建立一个数据库,并且添加数据。我建立的数据库如下。

二、建立LINQ to SQL映射。

然后一步步点确定
三、编写代码
在Controllers中建立控制器,模板为空。建立的项目如下:
要添加视图Index

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

注意后台要添加对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>
四、最终分页效果

代码下载地址: http://download.csdn.net/detail/luoyangwyb/7581651
MvcPager官方下载网址:http://mvcpager.codeplex.com/releases/view/47201
Demo的示例网址:http://en.webdiyer.com/
MVC中使用MVCPager简单分页的更多相关文章
- ASP.NET MVC中使用MvcPager异步分页+在分页中复选框下一页上一页也保持选中
ASP.NET MVC 分页使用的是作者杨涛的MvcPager分页控件 地址:http://www.webdiyer.com/mvcpager/demos/ajaxpaging/ 这个分页控件在里面 ...
- FineUIMvc随笔(6)对比WebForms和MVC中表格的数据库分页
声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 通过对比WebForms和MVC中表格数据库分页代码的不同,可以对 MVC 中的数据流转有更加深入的了解. WebForms 中 ...
- asp.net mvc 中 一种简单的 URL 重写
asp.net mvc 中 一种简单的 URL 重写 Intro 在项目中想增加一个公告的功能,但是又不想直接用默认带的那种路由,感觉好low逼,想弄成那种伪静态化的路由 (别问我为什么不直接静态化, ...
- MVC001之mvcpager简单分页
描述:用mvcpager实现简单分页功能 参考网址: http://www.cnblogs.com/iamlilinfeng/archive/2013/03/11/2951460.html http: ...
- asp.net -mvc框架复习(5)-ASP.NET MVC中的视图简单使用
1.视图分类 ASPX视图(现在讲解) Razor视图(后面讲解) ASPX 视图: 2.@page指令 作用:页面的声明 要求:必须放在第一行,常用指令属性如下: 3.服务器端内嵌语法 小脚本:在A ...
- 【MVC】使用MvcPager进行分页
1.添加引用: mvcPager 版本高的提供的功能也更多. 注:下载了第一个,但是里面的一些字段是只读的.(eg:PagedList<T> .TotalItemCount)这是不符合的. ...
- MVC中验证码的简单使用
首先新建一个MVC项目 添加类:验证码帮助类(ValidateCodeHelper) using System; using System.Collections.Generic; using Sys ...
- .net mvc中一种简单的工作流的设计
开篇前的废话:工作流是我们在做互联网应用开发时经常需要用到的一种技术,复杂的工作流我们基本是借助一些开源的 工作流项目来做,比如 ccflow等,但是有时候,我们只需要实现一些简单的工作流流程,这时候 ...
- mvc中hangfire全局简单配置
public void Configuration(IAppBuilder app) { ConfigureAuth(app); //指定使用Sql ...
随机推荐
- XML转换为HTML
from:http://www.w3school.com.cn/xml/xml_to_html.asp 在上一节中,我们讲解了如何通过 JavaScript 来解析 XML 并访问 DOM. 本例遍历 ...
- VMware一些使用心得
这段时间VMware workstation用得较多,装了好几个虚拟机,有win2003,win2008,win7,还分32位,64位.装了这么多,要么是用于安装一些软件,比如oracle12c,因为 ...
- SpringMVC_配置和注解--跟海涛学SpringMVC(和自己在项目中的实际使用的对比)
Spring2.5 之前,我们都是通过实现Controller 接口或其实现来定义我们的处理器类,就像前面介绍的 这里介绍的是Spring3.1的新特性,虽然现在我用的是spring4.2.6,不过基 ...
- appche配置访问限制
1. 禁止访问某些文件/目录增加Files选项来控制,比如要不允许访问 .inc 扩展名的文件,保护php类库:<Files ~ "\.inc$"> Order a ...
- 如何写好react组件
react 组件方面: 总结 React 组件的三种写法 及最佳实践 [涨经验] React组件编写思路(一) 使用react-router实现单页面应用时设置页面间过渡的两种方式 [翻译]基于 Cr ...
- TibetanFont | ཡིག་གཟུགས། | 藏文字体
1.Microsoft Himalaya 微软喜马拉雅字体 2007年1月30日,微软公司向全球市场同步发布了其最新操作系统Windows Vista,并自带藏文字体和输入法,Windows Vist ...
- AutoIT: WinActivate可以把要操作的窗口提前。
If WinExists("[CLASS:Notepad2]") Then Local $hWnd = WinWait() ; Convert the handle to a st ...
- pymemcache get start
Getting started! A comprehensive, fast, pure-Python memcached client library. Basic Usage from pymem ...
- 转载:百为STM32开发板教程之十二——NAND FLASH
http://bbs.21ic.com/icview-586200-1-1.html 百为STM32开发板教程之十二——NAND FLASH 参考资料:百为stm32开发板光盘V3\百为stm32开发 ...
- bzoj 4820: [Sdoi2017]硬币游戏【kmp+高斯消元】
有点神,按照1444的做法肯定会挂 注意到它的概率是相同的,所以可以简化状态 详见http://www.cnblogs.com/candy99/p/6701221.html https://www.c ...