最新下载
热门教程
- 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() %>
相关文章
- 王者荣耀新宫本武藏连招操作 2022新版宫本怎么玩攻略[多图] 05-08
- 代号鸢左慈紫藤醉日怎么样 05-08
- 塞尔达传说王国之泪大的佐纳乌能源获得方法攻略 05-08
- paypal官网安卓版2024 05-08
- 代号鸢左慈紫藤醉日怎么样 代号鸢5.9新地宫介绍 05-08
- 虎符交易所最新安卓版2024 05-08