最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Asp.net Mvc分页方法介绍
时间:2022-06-25 04:26:33 编辑:袖梨 来源:一聚教程网
在mvcweb项目中有个global.asax.cs文件中有下代码:
routes.maproute(
"default", // 路由名称
"{controller}/{action}/{id}", // 带有参数的 url
new { controller = "index", action = "index", id = urlparameter.optional } // 参数默认值
);
在pagecontroller.cs中,我们用:
public actionresult index(string id)
{
return view(new models.page(id));
}
红色字体部分名称必须要相同。
再来看models目录下page.cs的部分代码:
public page(string para)
{
int pagesize = 10;
pageparse sm = new pageparse(para, httpcontext.current.request.querystring);
int currentpage = strtoint(sm["page"], 1);
datasource ds = new datasource();//初始化数据源
int totalcount = ds.objlist.count;//总记录数
var q=ds.objlist.asqueryable
if (currentpage > 0) q = q.skip((currentpage - 1) * pagesize);
alist = q.take(pagesize).tolist();
paging = new paging
}
<%=model.paging.getstr() %>
相关文章
- 塞尔达传说王国之泪伊乔欧神庙怎么打 05-11
- 《下一站江湖2》藩王密宝攻略 05-11
- 《夜族崛起》无暇者攻略 05-11
- 《庄园领主》供给率100%方法 05-11
- 《颂钟长鸣》能否骑马说明 05-11
- 《非生物因素》获得子弹方法 05-11