项目分页通用页

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了项目分页通用页相关的知识,希望对你有一定的参考价值。

首先在需要分页的table 下引入这行代码(引入已经准备好的通用分页)
@html.Partial("~/Views/Shared/_Pagination.js.cshtml",ViewData)

 

只需要在控制器设置两个参数

public ActionResult ProjectNode(string flowNodeId,int currentPageIndex = 1)
{
int totalCount;

//在以下方法里做分页操作 主要参数 currentPageIndex totalCount
var result = _projectNodeDomainService.GetProjectNodeList(flowNodeId,currentPageIndex, out totalCount);
ViewBag.allConuts = totalCount;
ViewBag.allPages = totalCount % 10 == 0 ? totalCount / 10 : (totalCount / 10) + 1;
return View(result.Results);
}

 

 

以下是分页代码

<div class="modal-footer no-margin-top" style="width: 100%;">
@{
int pageTotal = Convert.ToInt32(Request["pageTotal"]);
int dataCount = 0;
string toolName = "tool.Paging";
if (ViewData["toolName"] != null)
{
toolName = ViewData["toolName"].ToString() + "";
}
if (ViewData["pageTotal"] != null)
{
pageTotal = Convert.ToInt32(ViewData["pageTotal"]);
}
if (ViewData["dataCount"] != null)
{
dataCount = Convert.ToInt32(ViewData["dataCount"]);
}
if (Request["dataCount"] != null)
{
dataCount = Convert.ToInt32(Request["dataCount"]);

}
int currentPageIndex = Convert.ToInt32(Request["currentPageIndex"]);
if (pageTotal <= 1)
{

pageTotal = 1;
}
if (currentPageIndex <= 1)
{
currentPageIndex = 1;
}
if (currentPageIndex >= pageTotal)
{
currentPageIndex = pageTotal;
}

var count = Convert.ToInt32(ViewData["ShowPageTotal"]);
var skip = 5;
int startPage = currentPageIndex - 5 > 0 ? currentPageIndex - 5 : 0;
int endPage = currentPageIndex + 5 < pageTotal ? currentPageIndex + 5 : pageTotal;
if (count != 0)
{
skip = count % 2 == 0 ? count / 2 : count / 2 + 1;
startPage = currentPageIndex - skip > 0 ? currentPageIndex - skip : 0;
endPage = currentPageIndex + skip < pageTotal ? currentPageIndex + skip : pageTotal;

}
else
{
if (startPage == 0 & pageTotal >= 10)
{
endPage = 5;
}

//else
//{
// skip = count % 2 == 0 ? count / 2 : count / 2 + 1;
// endPage = currentPageIndex + skip < pageTotal ? currentPageIndex + skip : pageTotal;
//}
}

<div style="float: left;margin-left: 35%;">

<ul class="pagination pull-right no-margin" style="margin-top: 2px; text-align: right;float:none !important;">
<li class="prev">
<a href="javascript:@toolName (1)" style="font-size: 12px; color: black; float: inherit; padding: 4px 12px;">
首页
</a>
<a href="javascript:@toolName (@currentPageIndex-1)" style="font-size: 12px; color: black; float: inherit; padding: 4px 12px;">
上一页
</a>
</li>
@for (int i = startPage; i < endPage; i++)
{
int pageIndex = i + 1;
if (currentPageIndex == pageIndex)
{
<li class="active">
<a href="javascript:@toolName (@pageIndex)" style="font-size: 12px; color: black; float: inherit; padding: 4px 12px;">@pageIndex</a>
</li>
}
else
{
<li>
<a href="javascript:@toolName (@pageIndex)" style="font-size: 12px; color: black; float: inherit; padding: 4px 12px;">@pageIndex</a>
</li>
}

}
<li class="next">
@if (currentPageIndex >= pageTotal)
{
<a href="javascript:@toolName (@currentPageIndex)" style="font-size: 12px; color: black; float: inherit; padding: 4px 12px;">
下一页
</a>
}
else
{
<a href="javascript:@toolName (@currentPageIndex+1)" style="font-size: 12px; color: black; float: inherit; padding: 4px 12px;">
下一页
</a>
}
<a href="javascript:@toolName (@pageTotal)" style="font-size: 12px; color: black; float: inherit; padding: 4px 12px;">
尾页
</a>

@*<input type="text" class="form-control" style="width:10%;display:initial; max-height: 27px;padding: 4px 12px;" id="txtPageIndex" />
<a onclick="SelectPange();" style="font-size:12px;color:black;float:inherit;padding: 4px 12px;">跳转</a>*@
</li>
</ul>

<label style="font-weight: inherit">
共 @*<b class="redcfldcn">*@@[email protected]*</b>*@ 页,
@if (dataCount != 0)
{
<span id="datacount">@dataCount</span>
}
当前页码: @*<b class="redcfldcn">*@@[email protected]*</b>*@
</label>
</div>
}

</div>

以上是关于项目分页通用页的主要内容,如果未能解决你的问题,请参考以下文章

通用权限管理系统中的分页解决方案

Springboot集成mybatis通用Mapper与分页插件PageHelper(推荐)

通用分页后台显示

.net通用CMS快速开发框架——问题:Dapper通用的多表联合分页查询怎么破?

通用分页查询存储过程

bos 第4 (区域excel批量导入区域通用分页查询分区的添加分区多条件分页查询分区导出excel)