首页 > 代码库 > 项目分页通用页
项目分页通用页
首先在需要分页的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">*@@pageTotal@*</b>*@ 页,
@if (dataCount != 0)
{
<span id="datacount">@dataCount</span>
}
当前页码: @*<b class="redcfldcn">*@@currentPageIndex@*</b>*@
</label>
</div>
}
</div>
项目分页通用页