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 ...
随机推荐
- Android ----------获取各种路径(更新中。。。。。。)
##在手机中的路径 *获取应用的路径,形式:/data/data/包名 String appDataDir = getApplicationInfo().dataDir; *获取手机数据存储路径,即/ ...
- SilverLight 页面后台方法XX.xaml.cs 创建JS,调用JS ,弹出提示框
1.Invoke和InvokeSelf [c-sharp] view plaincopy public partial class CreateJSDemo : UserControl { publi ...
- ios文件读取(二)
- (void)viewDidLoad { [super viewDidLoad]; /** * @brief 获取文件路径 * */ NSString * filePath = [self get ...
- 给一组a标签当前页a标签加class
<script type="text/javascript"> $(document).ready(function(){ $(".links .topbg_ ...
- JDK PATH 和 CLASSPATH环境变量的作用及其配置
(1)PATH环境变量的作用 在安装JDK程序之后,在安装目录下的bin目录中会提供一些开发Java程序时必备的工具程序. 对于Java的初学者,建议在命令符模式下使用这些工具程序编译运行Java程序 ...
- Android中读取assets文件夹中的子文件夹内容
文件结构如下:assets/info/info AssetManager am = this.getResources().getAssets(); InputStream input = null; ...
- hdu 3047 Zjnu Stadium
http://acm.hdu.edu.cn/showproblem.php?pid=3047 带权并差集 #include <cstdio> #include <cstring> ...
- BZOJ 2324 营救皮卡丘
http://www.lydsy.com/JudgeOnline/problem.php?id=2324 思路:最小费用最大流 考虑设数组d[k][i][j],代表只用前k个城市,i到j的最短路 然后 ...
- HDU 4035 Maze(树形概率DP)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4035 题意:一棵树,从结点1出发,在每个结点 i 都有3种可能:(1)回到结点1 , 概率 Ki:(2 ...
- 快速入门:触摸输入(使用 C#/VB/C++ 和 XAML 的 Windows 应用商店应用)
原文 http://technet.microsoft.com/zh-cn/subscriptions/hh465387 快速入门:触摸输入(使用 C#/VB/C++ 和 XAML 的 Windows ...