//实现层
---------------------------------------------------------分割线---------------------------------------------------------
public List ShowListPage(int pageindex, int pagesize)
{
string sql = string.Format("select top({0}) *from (select ROW_NUMBER() over (order by Id)iid,*from UserType)fy where iid>(({1}-1)*{2})", pagesize, pageindex, pagesize);
DataTable dt = DBHelper.GetTable(sql);
var str = JsonConvert.SerializeObject(dt);
return JsonConvert.DeserializeObject>(str);
}
//控制器
---------------------------------------------------------分割线---------------------------------------------------------
public ActionResult ShowPage(int pageindex=1)
{
//一页显示2条数据
int pagesize = 2;
//记录总的条数
int pagecount = idal.ShowCount();
//当条数为总数时
if (pagecount % pagecount == 0)
{
ViewBag.fy = pagecount / pagesize;
}
else
{
ViewBag.fy = (pagecount / pagesize) + 1;
}
//页数
ViewBag.pageindex = pageindex;
ViewBag.pagesize = pagesize;
ViewBag.pagecount = pagecount;
ViewBag.list = idal.ShowListPage(pageindex, pagesize);
var resulr = idal.ShowCount();
return View(resulr);
}
//UI前台显示
---------------------------------------------------------分割线---------------------------------------------------------
@{
var shang = ViewBag.pageindex;
shang--;
if (shang < 0) { shang = 1; };
{
}
}
@{
var next = ViewBag.pageindex;
next++;
if (next > ViewBag.fy) { next = ViewBag.fy; };
{
}
}
SQL语句
---------------------------------------------------------分割线---------------------------------------------------------
--高老师传授的分页,毕生受用!!
select top(2) *from (select ROW_NUMBER() over (order by Id)iid,*from Exam02)fy where iid>((1-1)*2)