mvc PagerHelper静态分页
---------------分页方法-----------------
public static class PagerHelper
{
/// <summary>
/// 分页
/// </summary>
/// <param name="helper"></param>
/// <param name="id">分页id</param>
/// <param name="currentPageIndex">当前页</param>
/// <param name="pageSize">分页尺寸</param>
/// <param name="recordCount">记录总数</param>
/// <param name="htmlAttributes">分页头标签属性</param>
/// <param name="className">分页样式</param>
/// <param name="mode">分页模式</param>
/// <returns></returns>
public static string Pager(this HtmlHelper helper, string id, int currentPageIndex, int pageSize, int recordCount, object htmlAttributes, string className,PageMode mode)
{
TagBuilder builder = new TagBuilder("table");
builder.IdAttributeDotReplacement = "_";
builder.GenerateId(id);
builder.AddCssClass(className);
builder.MergeAttributes(new RouteValueDictionary(htmlAttributes));
builder.InnerHtml = GetNormalPage(currentPageIndex, pageSize, recordCount,mode);
return builder.ToString();
}
/// <summary>
/// 分页
/// </summary>
/// <param name="helper"></param>
/// <param name="id">分页id</param>
/// <param name="currentPageIndex">当前页</param>
/// <param name="pageSize">分页尺寸</param>
/// <param name="recordCount">记录总数</param>
/// <param name="className">分页样式</param>
/// <returns></returns>
public static string Pager(this HtmlHelper helper, string id, int currentPageIndex, int pageSize, int recordCount, string className)
{
return Pager(helper, id, currentPageIndex, pageSize, recordCount, null, className,PageMode.Normal);
}
/// <summary>
/// 分页
/// </summary>
/// <param name="helper"></param>
/// <param name="id">分页id</param>
/// <param name="currentPageIndex">当前页</param>
/// <param name="pageSize">分页尺寸</param>
/// <param name="recordCount">记录总数</param>
/// <returns></returns>
public static string Pager(this HtmlHelper helper,string id,int currentPageIndex,int pageSize,int recordCount)
{
return Pager(helper, id, currentPageIndex, pageSize, recordCount,null);
}
/// <summary>
/// 分页
/// </summary>
/// <param name="helper"></param>
/// <param name="id">分页id</param>
/// <param name="currentPageIndex">当前页</param>
/// <param name="pageSize">分页尺寸</param>
/// <param name="recordCount">记录总数</param>
/// <param name="mode">分页模式</param>
/// <returns></returns>
public static string Pager(this HtmlHelper helper, string id, int currentPageIndex, int pageSize, int recordCount,PageMode mode)
{
return Pager(helper, id, currentPageIndex, pageSize, recordCount, null,mode);
}
/// <summary>
/// 分页
/// </summary>
/// <param name="helper"></param>
/// <param name="id">分页id</param>
/// <param name="currentPageIndex">当前页</param>
/// <param name="pageSize">分页尺寸</param>
/// <param name="recordCount">记录总数</param>
/// <param name="className">分页样式</param>
/// <param name="mode">分页模式</param>
/// <returns></returns>
public static string Pager(this HtmlHelper helper, string id, int currentPageIndex, int pageSize, int recordCount,string className, PageMode mode)
{
return Pager(helper, id, currentPageIndex, pageSize, recordCount, null,className,mode);
}
/// <summary>
/// 获取普通分页
/// </summary>
/// <param name="currentPageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="recordCount"></param>
/// <returns></returns>
public static string GetNormalPage(int currentPageIndex, int pageSize, int recordCount,PageMode mode)
{
int pageCount = (recordCount%pageSize ==0?recordCount/pageSize:recordCount/pageSize+1);
StringBuilder url = new StringBuilder();
url.Append(HttpContext.Current.Request.Url.AbsolutePath+"?page={0}");
NameValueCollection collection = HttpContext.Current.Request.QueryString;
string[] keys = collection.AllKeys;
for (int i = 0; i < keys.Length; i++)
{
if (keys[i].ToLower() != "page")
url.AppendFormat("&{0}={1}", keys[i], collection[keys[i]]);
}
StringBuilder sb = new StringBuilder();
sb.Append("<tr><td>");
sb.AppendFormat("总共{0}条记录,共{1}页,当前第{2}页 ", recordCount, pageCount, currentPageIndex);
if (currentPageIndex == 1)
sb.Append("<span>首页</span> ");
else
{
string url1 = string.Format(url.ToString(), 1);
sb.AppendFormat("<span><a href={0}>首页</a></span> ", url1);
}
if (currentPageIndex > 1)
{
string url1 = string.Format(url.ToString(), currentPageIndex - 1);
sb.AppendFormat("<span><a href={0}>上一页</a></span> ", url1);
}
else
sb.Append("<span>上一页</span> ");
if(mode == PageMode.Numeric)
sb.Append(GetNumericPage(currentPageIndex,pageSize,recordCount,pageCount,url.ToString()));
if (currentPageIndex < pageCount)
{
string url1 = string.Format(url.ToString(), currentPageIndex+1);
sb.AppendFormat("<span><a href={0}>下一页</a></span> ", url1);
}
else
sb.Append("<span>下一页</span> ");
if (currentPageIndex == pageCount)
sb.Append("<span>末页</span> ");
else
{
string url1 = string.Format(url.ToString(), pageCount);
sb.AppendFormat("<span><a href={0}>末页</a></span> ", url1);
}
return sb.ToString();
}
/// <summary>
/// 获取数字分页
/// </summary>
/// <param name="currentPageIndex"></param>
/// <param name="pageSize"></param>
/// <param name="recordCount"></param>
/// <param name="pageCount"></param>
/// <param name="url"></param>
/// <returns></returns>
private static string GetNumericPage(int currentPageIndex, int pageSize, int recordCount, int pageCount,string url)
{
int k = currentPageIndex / 10;
int m = currentPageIndex % 10;
StringBuilder sb = new StringBuilder();
if (currentPageIndex / 10 == pageCount / 10)
{
if (m == 0)
{
k--;
m = 10;
}
else
m = pageCount%10;
}
else
m = 10;
for (int i = k * 10 + 1; i <= k * 10 + m; i++)
{
if (i == currentPageIndex)
sb.AppendFormat("<span><font color=red><b>{0}</b></font></span> ", i);
else
{
string url1 = string.Format(url.ToString(), i);
sb.AppendFormat("<span><a href={0}>{1}</a></span> ",url1, i);
}
}
return sb.ToString();
}
}
/// <summary>
/// 分页模式
/// </summary>
public enum PageMode
{
/// <summary>
/// 普通分页模式
/// </summary>
Normal,
/// <summary>
/// 普通分页加数字分页
/// </summary>
Numeric
}
----------------------------控制器调用----------------------------------------------
public ActionResult Index()
{
//多个动作可以使用隐藏控件值判断
int pageIndex = GetRequestInt("page") < 1 ? 1 : GetRequestInt("page");
int pageSize = GetRequestInt("pagesize") < 1 ? 10 : GetRequestInt("pagesize");
//string key = GetRequestString("key").Replace(",", "");//关键字
//string checkstatus = GetRequestString("checkstatus");//审核状态
////检查是否有删除
//string DelIdString = GetRequestString("cbSelected");
//if (!string.IsNullOrEmpty(DelIdString))
//{
// foreach (var item in DelIdString.Split(','))
// {
// string _id = item.Replace("'", "");
// db.Delete("dt_Job", "Id", null, _id);
// }
//}
//int count = 0;
//string _where = "1=1";
//if (checkstatus.Equals("0") || checkstatus.Equals("1"))
//{
// _where += " and CheckStatus=" + checkstatus;
//}
//if (!string.IsNullOrEmpty(key))
//{
// _where += string.Format(" and ( Name like '%{0}%' or ApplyOrganization like '%{0}%' )", key);
//}
//var temp = db.Page<Job>(pageIndex, pageSize, "select * from dt_Job where " + _where + " Order by CreateTime desc,id");
var temp = db.Page<Job>(pageIndex, pageSize, "select * from dt_Job Order by CreateTime desc,id");
//返回分页导航和列表
ListInfo Result = new ListInfo()
{
PageItemInfo = temp,
//key = key,
//checkstatus = checkstatus,
PageString = PagerHelper.GetNormalPage(pageIndex, pageSize, (int)temp.TotalItems, PageMode.Normal)
};
return View(Result);
}
-------------------------------------------------------------html页面显示-----------------------------------------------------------------------
<form method="get" id="flist" name="flist">
@*<div id="content">
<div class="tools_box">
<div class="tools_bar">
<div class="search_box">
<input name="key" type="text" id="txtKeywords" class="txtInput" value="@Model.key">
<input type="submit" name="submit" value="搜索" id="submit" class="btnSearch">
</div>
<a href="javascript:void(0);" onclick="checkAll(this);" class="tools_btn"><span><b class="all">全选</b></span></a>
@* <a id="LinkButton2" class="tools_btn" href="javascript:__doPostBack('LinkButton2','')"><span><b class="send">全部审核</b></span></a>
<a onclick="return delJob('btnDelete');" id="btnDelete" class="tools_btn" href="javascript:void(0)"><span><b class="delete">批量删除</b></span></a>
</div>
<div class="select_box">
请选择:
<select name="checkstatus" onchange="tijiao()" id="checkstatus" class="select2">
<option value="">所有属性</option>
<option value="1" @{if (@Model.checkstatus=="1"){string res="selected";@res }}>已审核</option>
<option value="0" @{if (@Model.checkstatus=="0"){string res="selected";@res }}>未审核</option>
</select>
</div>
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" class="msgtable">
<tbody>
<tr class="tr_odd_bg">
<th width="6%">选择</th>
<th width="150" align="left">姓名</th>
<th align="left">报考单位</th>
<th align="left">岗位及代码</th>
<th width="160">申请时间</th>
<th width="120">审核状态</th>
<th width="100">浏览</th>
</tr>
@foreach (var item in Model.PageItemInfo.Items)
{
<tr class="">
<td align="center" class="checkall"> <input type="checkbox" name="cbSelected" value="@item.Id" /> </td>
<td>@item.Name</td>
<td>@item.ApplyOrganization</td>
<td>@item.ApplyCode</td>
<td align="center">@item.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")</td>
<td align="center">
@{if (item.CheckStatus == 1)
{
string res = "已审核";
@res
}
else
{
string res = "<font color='red'>未审核</font>";
@Html.Raw(res)
}
}
</td>
<td align="center">@Html.ActionLink("查看", "Detail", new { id = item.Id }, new { target = "_blank" }) </td>
</tr>
}
</tbody>
</table>
<div class="line15"></div>*@
<div class="page_box">
<div id="PageContent" class="flickr right">@Html.Raw(Model.PageString)</div>
<div class="left">
显示<input name="pagesize" type="text" value="@Model.PageItemInfo.ItemsPerPage" onchange="tijiao()" id="pagesize" class="txtInput2 small2">条/页
</div>
</div>
</div>
</form>
mvc PagerHelper静态分页的更多相关文章
- Spring MVC 处理静态资源文件
摘要: 三个方案: 1.方案一:激活Tomcat的defaultServlet来处理静态文件 2.方案二: 在spring3.0.4以后版本提供了mvc:resources (需要配置annotati ...
- asp.net mvc多条件+分页查询解决方案
开发环境vs2010 css:bootstrap js:jquery bootstrap paginator 原先只是想做个mvc的分页,但是一般的数据展现都需要检索条件,而且是多个条件,所以就变成了 ...
- thinkPHP生成静态分页列表
改造分页类Pagehtml.class.php <?php // 静态分页列表类 class Pagehtml extends Think { //分页url public $pageUrl; ...
- ASP.NET MVC利用PagedList分页(二)PagedList+Ajax+JsRender
(原文) 昨天在ASP.NET MVC利用PagedList分页(一)的 最后一节提到,一个好的用户体验绝对不可能是点击下一页后刷新页面,所以今天来说说利用Ajax+PagedList实现无刷新(个人 ...
- HTML静态分页(形如:首页,上一页,下一页,尾页)
在HTML中有时候我们会用到静态分页,一次拿回一定量的数据结果条目,我们会以形如:第2页,共12页 首页 上一页 下一页 尾页 的方式进行静态分页,以下是该种静态分页的代码,供兄弟姐妹们参考. &l ...
- MVC无刷新分页
MVC无刷新分页(即局部刷新,带搜索,页数选择,排序功能) 我查看了很多网站,大部分评论分页都是局部刷新的,可大部分电商商品展示分页都是有刷新页面的,于是我便做了一个商品展示无刷新分页的例子.接下 ...
- Asp.Net MVC页面静态化功能实现二:用递归算法来实现
上一篇提到采用IHttpModule来实现当用户访问网站的时候,通过重新定义Response.Filter来实现将返回给客户端的html代码保存,以便用户下一次访问是直接访问静态页面. Asp.Net ...
- Asp.Net MVC页面静态化功能实现一:利用IHttpModule,摒弃ResultFilter
上一篇有提到利用IHttpModule和ResultFilter实现页面静态化功能.后来经过一些改动,将ResultFilter中要实现的功能全部转移到IHttpModule中来实现 Asp.Net ...
- Asp.Net MVC页面静态化功能实现一:利用IHttpModule和ResultFilter
由于公司现在所采用的是一套CMS内容管理系统的框架,所以最近项目中有一个需求提到要求实现页面静态化的功能.在网上查询了一些资料和文献,最后采用的是小尾鱼的池塘提供的 利用ResultFilter实现a ...
随机推荐
- Katana概述
OWIN owin是web services和framework组件之间的抽象.抽象包括两个核心要素: environment dictionary 这个数据结构存储处理HTTP请求必须的状态和相关的 ...
- EF数据存贮问题二之“无法定义这两个对象之间的关系,因为它们附加到不同的 ObjectContext 对象”
“无法定义这两个对象之间的关系,因为它们附加到不同的 ObjectContext 对象”,这是在EF中,一对多关系表,有外键的类保存至数据库中出现的错误. 我原来是用JAVA开发的,习惯性的处理一对多 ...
- 在msvc中使用Boost.Spirit.X3
Preface “Examples of designs that meet most of the criteria for "goodness" (easy to unders ...
- Jquery函数实现时间显示模式为更新于+被当前时间减去后剩余的时间值(例如:更新于三小时前)的处理。
var time_eles = $(".time_tranfer"); for(var i =0; i < time_eles.length;i++){ var time_e ...
- keil中查看内存数据
1.工具栏中 view->Memory Windows 然后 c:0 表示读取0地址开始的代码区数据 d:0 表示读取0地址开始的数据区数据 x:0表示读取0地址开始的外部数据区
- “Win”组合键
Windows组合键功能: 单独按下显示或隐藏 [开始] 功能表. +Break 显示 [系统内容] 对话方块. +D 显示桌面. +M 最小化所有的视窗. +Shift+M 还原最小化的视窗. +E ...
- Java消息服务
什么是消息? 消息是可编程实现两端通信的机制.通常的一些消息技术如:TCP/IP Sockets.管道.文件.共享存储. Java消息服务 Java消息服务,即Java Message Service ...
- 手把手教你如何使用webpack+react
上一篇随笔讲述了新手入门入门前端 里面提到的第四阶段跟上当前前端的发展需要入门一个框架和自动化工具,当时推荐的是webpack+react 今天正好有空,也把自己入门webpack + react 的 ...
- C语言内存分配函数
c语言标准库提供了3个内存分配的函数,都包含在头文件<stdlib.h>中 1.malloc 函数原型: void *malloc( size_t size ); 参数:要分配内存大小的字 ...
- NFine常见错误
1.新增数据录入录入不进去提示:An error occurred while updating the entries.See the inner exception for details. 这样 ...