整个过程主要就是:一开始进入页面是,在页面加载完成之后直接通过$(function(){  LoadRegisterUserInfo(1,10,0,0);//加载注册用户信息 });无条件加载数据,调用的方法可以查看下面的js代码。接着就是按条件查询数据,主要把条件查询的方式(searchWay)和查询的条件(condition)提交处理接受返回数据。(新手代码,性能方面估计没想太多,如有不足之处,敬请提出,本着学习交流的态度)

①Html代码(UserManager.cshtml),展示分页数据

  <div>
<div>
<h4><span style="padding-bottom:100px;">【快速搜索】</span></h4> <span style="margin-top:10px;">
<span id="UserManagerSearchSpan">
&nbsp;<input type="button" value="查看所有用户" style="background-color:#33FFCC;border-style:solid;border-width:1px;border-radius:6px;" onclick="LoadRegisterUserInfo(1,10,0,0)" /> &nbsp;&nbsp;&nbsp;&nbsp;
角色:<select id="search_role">
@if (Session["AdminLevel"].ToString() == "0")
{
<option value="1">学生</option>
<option value="2">教师</option>
<option value="3">管理员</option>}
else
{
<option value="1">学生</option><option value="2">教师</option> }
</select>
<span><input type="button" value="按角色查询" onclick="LoadRegisterUserInfo(1,10,1,1)" /> </span><span>
&nbsp;&nbsp;&nbsp;&nbsp;
登录账号:<input type="text" id="search_accountNumber" data-toggle="tooltip" data-placement="top" title="<h5> <span class='myTipTitleColor'>请填写有效的账号!</span></h5>"/>
</span><span><input type="button" value="按账号查询" onclick="LoadRegisterUserInfo(1, 10, 2, 0)" /> </span><span>
&nbsp;&nbsp;&nbsp;&nbsp;
姓名:<input type="text" id="search_name" data-toggle="tooltip" data-placement="top" title="<h5> <span class='myTipTitleColor'>请填写用户的姓名!</span></h5>" />
</span><span><input type="button" value="按姓名查询" onclick="LoadRegisterUserInfo(1, 10, 3, 0)" /> </span>
</span>
</span>
</div>
<hr />
<div id="UserManageTablePlace">
<table id="RegisterUserInfoTable">
<tr class="mytr3"><th>编号</th><th>登录账号</th><th>姓名</th><th>性别</th><th>证件号码</th><th>用户类型</th><th>操作</th></tr>
</table>
<table id="UserStateTable" style="display:none">
<tr class="mytr3"><th>编号</th><th>登录账号</th><th>姓名</th><th>性别</th><th>证件号码</th><th>用户类型</th><th>操作</th></tr>
</table>
</div>
<br />
<div class="myPage">
<span class="myShowPage">
<!--这里放页码导航-->
</span> </div>
<br />
</div>

Html代码

②C#代码,主要回去返回需要展示的数据(AdminController.cs)

  /*
* 这里除了一次性第一次无条件查询之外,还可以处理根据不同条件去查询
*
* searchWay(0--无条件查询,即系查询所有,1--按角色查询,2--按账号查询,3---按名字查询)
* condition(0---无条件查询.。如果按角色查询(1---按学生角色查询,2---按教师角色查询,3--按管理员角色查询)。如果是按账号查询,则此时的condition就是需要查询的账号。如果为按名字查询,则此时的condition就是需要查询的名字)
*
*/
//②加载【所有待验证的注册用户】的信息
List<AllUserInfo> AllList = AllUserInfo.GetAllRegisterUserInfo(Session["AdminLevel"].ToString());
List<AllUserInfo> AllList2 = new List<AllUserInfo>();//放筛选之后的数据
int pageSize = Request["pageSize"] == null ? : int.Parse(Request["pageSize"]);
int pageIndex = Request["pageIndex"] == null ? : int.Parse(Request["pageIndex"]); //判断是否是条件筛选
string searchWay = Request["searchWay"];
string condtition = Request["condition"];
if (!string.IsNullOrEmpty(searchWay) && !string.IsNullOrEmpty(condtition))//条件筛选
{
int k1 = ;//记录序号
if (searchWay == "" && condtition == "")//都是0的代表是无条件查询
{
AllList2 = AllList;//无条件查询
}
else if (searchWay == "")//按角色去筛选
{
#region 筛选数据
string selectCondition; if (condtition == "")//【学生】
{
selectCondition = "学生";
}
else if (condtition == "")//【教师】
{
selectCondition = "教师";
}
else if (condtition == "")//【管理员】
{
selectCondition = "管理员";
}
else
{
return Content("没找到相关数据!");
} //遍历,筛选数据
foreach (AllUserInfo use in AllList)
{
if (use.Role == selectCondition)
{
use.ListID = k1;
AllList2.Add(use);
k1++;
}
}
#endregion }
else if (searchWay == "" && !string.IsNullOrEmpty(Request["selectCondition"].ToString()))//按账号查询
{ #region 遍历,筛选数据
string selectCondition = Request["selectCondition"];
foreach (AllUserInfo use in AllList)
{
if (use.UserNum == selectCondition)
{
use.ListID = k1;
AllList2.Add(use);
k1++;
}
}
#endregion
}
else if (searchWay == "" && !string.IsNullOrEmpty(Request["selectCondition"].ToString()))//按名字进行查找
{
#region 遍历,筛选数据
string selectCondition = Request["selectCondition"];
foreach (AllUserInfo use in AllList)
{
if (use.UserName == selectCondition)
{
use.ListID = k1;
AllList2.Add(use);
k1++;
}
}
#endregion
}
else
{
return Content("没找到相关数据!");
}
}
else
{
//searchWay = " ";
//condtition = " ";
//AllList2 = AllList;
} int total = AllList2.Count;//获取筛选之后的全部数据总的个数
ViewData["pageSize"] = pageSize;//每一页显示的条数
ViewData["pageIndex"] = pageIndex;//当前需要显示的页码
ViewData["total"] = total; List<AllUserInfo> RetList = new List<AllUserInfo>();//这个列表放需要显示页的数据
for (int i = pageSize * (pageIndex - ); i < pageSize * (pageIndex - ) + pageSize; i++)//根据页码和页的大小截取数据记录,然后放在RetList中
{
if (i == AllList2.Count)//如果到达列表结尾,直接跳出
{
break;
}
RetList.Add(AllList2[i]); } var json = new//格式化返回数据,转换成json
{
Total = RetList.Count,//返回数据的条数
Row = RetList.ToList(),//返回数据集合
PageNumber = Page.ShowPageNavigate(pageIndex,pageSize,total,searchWay,condtition)//这个方法为分页导航条的字符串
}; return Json(json, JsonRequestBehavior.AllowGet);//返回数据

C#代码

③分页导航处理生产字符串的方法(Page.cs)

 public class Page
{
public static string ShowPageNavigate( int currentPage, int pageSize, int totalCount,string searchWay, string condition)
{
pageSize = pageSize == ? : pageSize;
var totalPages = Math.Max((totalCount + pageSize - ) / pageSize, ); //总页数
var output = new StringBuilder();
if (totalPages > )
{
//if (currentPage != 1)
{//处理首页连接
output.AppendFormat("<a class='pageLink' href='javascript:void(0);' onclick='LoadRegisterUserInfo({0},{1},{2},{3})'>首页</a> ", , pageSize,searchWay, condition);
}
if (currentPage > )
{//处理上一页的连接 output.AppendFormat("<a class='pageLink' href='javascript:void(0);' onclick='LoadRegisterUserInfo({0},{1},{2},{3})'>上一页</a> ", currentPage - , pageSize,searchWay, condition);
}
else
{
// output.Append("<span class='pageLink'>上一页</span>");
} output.Append(" ");
int currint = ;
for (int i = ; i <= ; i++)
{//一共最多显示10个页码,前面5个,后面5个
if ((currentPage + i - currint) >= && (currentPage + i - currint) <= totalPages)
{
if (currint == i)
{//当前页处理
//{0}?pageIndex={1}&pageSize={2}
output.AppendFormat("<a href='javascript:void(0);'><span class='currentPage'>{0}</span></a> ", currentPage);
//output.AppendFormat("<a class='active' href='javascript:void(0);'>{0}</a> ", currentPage);
}
else
{//一般页处理 output.AppendFormat("<a class='pageLink' href='javascript:void(0);' onclick='LoadRegisterUserInfo({0},{1},{2},{3})'>{4}</a> ", currentPage + i - currint, pageSize,searchWay, condition, currentPage + i - currint);
}
}
output.Append(" ");
}
if (currentPage < totalPages)
{//处理下一页的链接 output.AppendFormat("<a class='pageLink' href='javascript:void(0);' onclick='LoadRegisterUserInfo({0},{1},{2},{3})'>下一页</a> ", currentPage + , pageSize,searchWay,condition);
}
else
{
//output.Append("<span class='pageLink'>下一页</span>");
}
output.Append(" ");
if (currentPage != totalPages)
{ output.AppendFormat("<a class='pageLink' href='javascript:void(0);' onclick='LoadRegisterUserInfo({0},{1},{2},{3})'>末页</a> ", totalPages, pageSize,searchWay,condition);
}
output.Append(" ");
}
output.AppendFormat("第{0}页 / 共{1}页", currentPage, totalPages);//这个统计加不加都行 return output.ToString();
}
}

C# Page类的处理方法

④Js处前端和后端的交互(adminJS2.js)

 $(function () {
$('[data-toggle="tooltip"]').tooltip({ html: true });
LoadRegisterUserInfo(,,,);//加载注册用户信息
}); //SaveSearchWay = "";
//SaveCondition = ""; /// <summary>
/// 加载注册【用户信息】
/// </summary>
/// <param name="pageIndex">页号</param>
/// <param name="pageSize">显示条数</param>
/// <param name="searchWay">搜索方式</param>
/// <param name="condition">条件</param>
/// <returns></returns>
function LoadRegisterUserInfo(pageIndex, pageSize,searchWay,condition) {
//alert(searchWay + "____" + condition);
//alert(pageIndex + "_______" + pageSize);
//【条件筛选】初始化数据
var selectCondition = ;
if (searchWay == "") {//【按照角色查找】
condition = $("#search_role").val();
}
if (searchWay == "") {//【按账号查找】
if ($("#search_accountNumber").val() != "") {
condition = ;
selectCondition = $("#search_accountNumber").val();
}
else {
alert("请填写需要查询的账号!");
return;
}
}
if (searchWay == "") {//【按照姓名查找】
if ($("#search_name").val() != "") {
condition = ;
selectCondition = $("#search_name").val();
} else {
alert("请填写需要查询的姓名!");
return;
}
} //①先清空原来的表格
$("#RegisterUserInfoTable tr:gt(0)").remove(); var k = ;
//②发生请求
$.post("/Admin/GetAllRegisterUserInfo", { "pageIndex": pageIndex, "pageSize": pageSize, "searchWay": searchWay, "condition": condition ,"selectCondition":selectCondition}, function (data) {
//alert(result["Grade1"]);
//alert("Total" + data["Total"]); if (data["Total"] <= ) {
$("#RegisterUserInfoTable").append("<tr class=' mytr2-1' align = 'left'><td colspan = '7'>暂无学生信息</td> </tr>");
}
//var str = "<a href=javascript:void(0); onclick=SaveScoreBtnClick('" + stuNum + "','" + courseNum + "')>保存</a>";
//alert(searchWay + "____" + condition); for (var i = ; i < data["Total"]; i++) { //拼接删除链接字符串
var str1 = "<a href=javascript:void(0); onclick=DeleteRegisterUser('" + data['Row'][i].UserNum + "','" + data['Row'][i].Role + "'," + data["Row"][i].ListID + ")>删除</a>" //拼接通过连接字符串
var str2 = "<a href=javascript:void(0); onclick=PassRegisterUser('" + data['Row'][i].UserNum + "','" + data['Row'][i].Role + "'," + data["Row"][i].ListID + ")>通过</a>" if (k == ) {//处理隔行不同样式展示
$("#RegisterUserInfoTable").append("<tr class='mytr2 mytr2-1' id= "+data["Row"][i].ListID+"><td>" + data["Row"][i].ListID + "</td><td>" + data["Row"][i].UserNum + "</td><td>" + data["Row"][i].UserName + "</td><td>" + data["Row"][i].Sex + "</td><td>" + data["Row"][i].IdentityCard + "</td><td>" + data["Row"][i].Role + "</td><td>"+str1+" | "+str2+"</td></tr>");
k = ;
}
else {
$("#RegisterUserInfoTable").append("<tr class=' mytr2-1' id=" + data["Row"][i].ListID + "><td>" + data["Row"][i].ListID + "</td><td>" + data["Row"][i].UserNum + "</td><td>" + data["Row"][i].UserName + "</td><td>" + data["Row"][i].Sex + "</td><td>" + data["Row"][i].IdentityCard + "</td><td>" + data["Row"][i].Role + "</td><td>" + str1 + " | " + str2 + "</td></tr>");
k = ;
}
} $(".myShowPage").html("");
$(".myShowPage").html(data["PageNumber"]);//填充处理数据 }); }

Js代码

实现Asp.Net MVC无刷新分页的更多相关文章

  1. MVC无刷新分页

    MVC无刷新分页(即局部刷新,带搜索,页数选择,排序功能)   我查看了很多网站,大部分评论分页都是局部刷新的,可大部分电商商品展示分页都是有刷新页面的,于是我便做了一个商品展示无刷新分页的例子.接下 ...

  2. ASP.NET中无刷新分页

    上次介绍了我们代码写的刷新分页,这次就来说说无刷新分页. 这次我们是在上次的基础上改动了一些,我们都知道想要无刷新,就需要Ajax,在我们的ASP.NET中AJax是和一般处理程序配合着用的. 无刷新 ...

  3. MVC无刷新分页(即局部刷新,带搜索,页数选择,排序功能)

    我查看了很多网站,大部分评论分页都是局部刷新的,可大部分电商商品展示分页都是有刷新页面的,于是我便做了一个商品展示无刷新分页的例子.接下来我就将做一个模仿淘宝已买到的宝贝功能,不过我的是无刷新分页的. ...

  4. asp.net mvc 无刷新加载

    1.视图(index) <!--start--> <div data-am-widget="list_news" class="am-list-news ...

  5. MvcPager无刷新分页,包含搜索和跳转功能

    1.MVC无刷新分页和搜索(第一版)  http://pan.baidu.com/s/1eRQ7Ml8  密码:uqf7 出现的问题: 1)程序不走判断条件一直为false, 错误原因:1)可能没有引 ...

  6. MVC简单分页(未实现无刷新分页)

    分页Html辅助方法 using System.Text; using System.Web: using System.Web.Mvc; namespace System.Web.Mvc { pub ...

  7. asp.net MVC4 +MVCpager 无刷新分页

    本人菜鸟,最近在用MVC4和MVCpager做无刷新分页时,发现点击下一页时数据不是Ajax提交的,弄了好久终于找到原因,原来还是Jquery引用的问题,现在把代码粘出来,希望能帮到刚接触的程序员,第 ...

  8. ASP.NET Ajax简单的无刷新分页

    最近练习了一些AJAX无刷新分页,写得比较简单,性能不知道怎么样,求大神指点,如有更好的分页提供,欢迎交流! 发话不多说了,直接上代码! 首先从网上下了一个JS分页,感觉挺好用的 (function( ...

  9. asp.net练习②——Paginaton无刷新分页

    aspx代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server" ...

随机推荐

  1. leetcode 111

    题目描述: Given a binary tree, find its minimum depth. The minimum depth is the number of nodes along th ...

  2. 《30天自制操作系统》14_day_学习笔记

    harib11a--harib11c: 继续测试性能:我们在harib10h中进行了定时链表结构的改进“消除了移位处理”.下面我们设定490个定时器(它们都被设定启动50天才超时)来测试一下改进的效果 ...

  3. python实现并行爬虫

    问题背景:指定爬虫depth.线程数, python实现并行爬虫   思路:    单线程 实现爬虫类Fetcher                 多线程 threading.Thread去调Fet ...

  4. [Phalcon] Phalcon系统默认事件列表

    版本: 2.0.6 Phalcon\Mvc\Application application:boot 可终止 是 参数 Phalcon\Events\Event $event 事件本身 Phalcon ...

  5. Hibernate 简单使用

    首先在数据库中创建相应的表,脚本如下: create table Student (id int primary key, sName ), sNO ), sex ), email )) 在Myecl ...

  6. degign new theme for Filezilla(Mac OS X)

    the theme directory is located at Filezilla.app/Contents/SharedSupport/resources/ the dirs (excludin ...

  7. tomcat普通用户运行

    网站绑定域名后直接通过域名访问使用的是80端口,因此tomcat须监听80端口,而为了安全起见tomcat一般不用root身份运行,综上,需要以普通用户来运行监听80端口的tomcat.此时就会启动失 ...

  8. Linux系统软件

    ubuntu系统镜像文件: http://pan.baidu.com/s/1jGGgszO 虚拟机: http://pan.baidu.com/s/1hqrhQQg

  9. mac攻略(三) -- apache站点配置

    Mac OS X 中默认有两个目录可以直接运行你的 Web 程序, 一个是系统级的 Web 根目录:/Library/WebServer/Documents/ 此根目录我们平常使用地址http://l ...

  10. CentOS 7下关于systemd的一些唠叨话一:systemd的特点和使用

    摘要 近年来,Linux 系统的 init 进程经历了两次重大的演进,传统的 sysvinit 已经逐渐淡出历史舞台,新的 UpStart 和 systemd 各有特点,越来越多的 Linux 发行版 ...