VS - Paginated
BootstrapPagination.cshtml
@model PaginationModel
<div class="pagination">
<ul>
@foreach (var link in Model.PaginationLinks)
{
@BuildLink(link)
}
</ul>
</div> @helper BuildLink(PaginationLink link)
{
var liBuilder = new TagBuilder("li");
if (link.IsCurrent)
{
liBuilder.MergeAttribute("class", "active");
}
if (!link.Active)
{
liBuilder.MergeAttribute("class", "disabled");
} var aBuilder = new TagBuilder("a");
if (link.PageIndex != null) {
aBuilder.MergeAttribute("data-page", link.PageIndex.Value.ToString());
}
if (link.Url == null)
{
//aBuilder.MergeAttribute("href", "#");
}
else
{
aBuilder.MergeAttribute("href", link.Url);
aBuilder.AddCssClass("paging");
}
if (link.DisplayText == "«")
{
aBuilder.SetInnerText("←");
}
else if (link.DisplayText == "»")
{
aBuilder.SetInnerText("→");
}
else
{
aBuilder.SetInnerText(link.DisplayText);
}
liBuilder.InnerHtml = aBuilder.ToString(); @Html.Raw(liBuilder.ToString())
}
PaginatedList.cs
public class PaginatedList<T> : List<T> {
public int Offset { get; private set; }
public int PageIndex { get; private set; }
public int PageSize { get; private set; }
public int TotalCount { get; private set; }
public int TotalPages { get; private set; } /// <summary>
/// For manually paing.
/// </summary>
/// <param name="source">The result of current page</param>
/// <param name="totalCount"></param>
/// <param name="pageIndex"></param>
/// <param name="pageSize"></param>
public PaginatedList(IEnumerable<T> source, int totalCount, int pageIndex, int pageSize)
{
Offset = pageIndex * pageSize;
PageIndex = pageIndex;
PageSize = pageSize;
TotalCount = totalCount;
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize); this.AddRange(source);
} public PaginatedList(IQueryable<T> source, int pageIndex, int pageSize) {
Offset = pageIndex * pageSize;
PageIndex = pageIndex;
PageSize = pageSize;
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize); this.AddRange(source.Skip(PageIndex * PageSize).Take(PageSize));
} public PaginatedList(IQueryable<T> source, int pageSize, int? offset = null, int? pageIndex = null) {
if (offset != null) {
Offset = offset.Value;
PageIndex = (int)Math.Ceiling((decimal)Offset / pageSize);
} else if (pageIndex != null) {
Offset = pageIndex.Value * pageSize;
PageIndex = pageIndex.Value;
} else {
//offset = null and pageIndex = null
throw new ArgumentNullException("offset and pageIndex");
}
PageSize = pageSize;
TotalCount = source.Count();
TotalPages = (int)Math.Ceiling(TotalCount / (double)PageSize); this.AddRange(source.Skip(Offset).Take(PageSize));
} public bool HasPreviousPage {
get {
return (Offset > );
}
} public bool HasNextPage {
get {
return (Offset + PageSize < TotalCount);
}
} }
public PaginatedList<classname> classnameList { get; set; }
classnameList = new PaginatedList<EventCallDetail>(classList, count, (pageIndex > 0) ? pageIndex - 1 : 0, PageSize);
@Html.Pager(PageSize, PageIndex + 1, classnameList.TotalCount).Options(o => o.DisplayTemplate("BootstrapPagination"))
VS - Paginated的更多相关文章
- MyBatis(3.2.3) - Paginated ResultSets using RowBounds
Sometimes, we may need to work with huge volumes of data, such as with tables with millions of recor ...
- 【神器】vimum在浏览器中键盘操作选择、复制、粘贴,键盘党的最爱
1.下载: http://files.cnblogs.com/files/quejuwen/vimum_extension_1_56.zip 2.开源:https://github.com/philc ...
- 据说年薪30万的Android程序员必须知道的帖子
Android中国开发精英 目前包括: Android开源项目第一篇--个性化控件(View)篇 包括ListView.ActionBar.Menu.ViewPager.Gallery.G ...
- ecstore-app接口
接口调用方式: 接口完整地址为:http://域名/index.php/wapapp/请求地址 比如获取商品信息就是 http://域名/index.php/wapapp/product.html 提 ...
- Android开源项目分类汇总
目前包括: Android开源项目第一篇——个性化控件(View)篇 包括ListView.ActionBar.Menu.ViewPager.Gallery.GridView.ImageView. ...
- android 很多牛叉布局github地址(转)
原文地址 http://blog.csdn.net/luo15309823081/article/details/41449929 点击可到达github-------https://github.c ...
- zendframework 2 链接数据库
相对于zf1,来说,zf2让我们对于数据库这方面的操作我的个人感觉是对于字段起别名简单了,但是对数据库的操作虽然配置写好的就基本不需要动了,但是还是比1的配置要繁琐, 还是那句话,大家可以去看看源码. ...
- Yii的学习(5)--Active Record的关联
官网原文:http://www.yiiframework.com/doc/guide/1.1/zh_cn/database.arr 官网中后半段为英文,而且中文的内容比英文少一些,先放到这里,之后有时 ...
- vimium Keyboard Bindings
Modifier keys are specified as `<c-x>`, `<m-x>`, and `<a-x>` for ctrl+x, meta+x, a ...
随机推荐
- 【LEETCODE】35、169题, Majority Element
package y2019.Algorithm.array; import java.util.HashMap; import java.util.Map; /** * @ProjectName: c ...
- [高清·非影印]Spring实战+SpringBoot实战+Spring微服务实战+SpringCloud微服务实战(全4本)
------ 郑重声明 --------- 资源来自网络,纯粹共享交流, 如果喜欢,请您务必支持正版!! --------------------------------------------- 下 ...
- tomcat线程池调优
之前项目一直在tomcat下开发,后来在上线之前,需要进行性能安全测试,可是测试的同事反应,登陆口线程并发一多的时候,系统立马就没法登陆了. 中间件是tomcat6. tomcat的日志总是简洁的很 ...
- docker 入坑3
查看镜像 docker images [OPTIONS] [REPOSITORY[:TAG]] -a, --all=false -f, --filter=[] --no-trunc=false -q, ...
- 转 Html转pdf的工具——wkhtmltopdf
下载地址:http://wkhtmltopdf.org/downloads.html 安装好以后需要在系统环境变量变量名为”Path”的后添加:;D:\wkhtmltopdf\bin 也就是你安装的目 ...
- ubuntu gcc 降级 适应matlab
一.安装gcc 4.7 Ubuntu14.04自带的gcc版本是4.8,MATLAB2014a支持的最高版本为4.7x.因此,需要安装gcc4.7,并给gcc降级 在终端执行gcc 4.7的安装命令: ...
- Mac 磁盘分区格式
Mac 磁盘分区格式 来源 https://www.chadou.me/p/190 参考文章 macOS磁盘工具帮助 在Mac系统中抹掉(格式化)磁盘的时候,要求选择分区方案,包括GUID分区图.主引 ...
- Steam之两个list间交集、并集、差集
public static void main(String[] args) { List<String> list1 = new ArrayList(); list1.add(" ...
- tp框架防止表单重复提交
转载 框架官方 http://www.thinkphp.cn/topic/9090.html 第三方 https://my.oschina.net/caomenglong/blog/728908
- 获取新技能 ----dispaly: tabel
刚才在总结自适应布局的时候,灵光一现,好像记得哪位大佬提过 display: tabel 这个布局,然后就去查了一下资料,进行了学习,现在简单总结一下. 说白了就是可以给HTML元素指定与表格相关的d ...