最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
Asp.net Mvc分页方法介绍
时间:2011-02-02 编辑:简简单单 来源:一聚教程网
在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() %>
-
上一个: C#] 打印出不断长大的文字
相关文章
- ASP.NET MVC分页控件 03-26
- ASP.NET MVC分页问题解决方法 02-08
- C#复制数组的两种方式及效率比较解读 10-24
- ASP.NET Identity用法解析 10-24
- ASP.NET MVC使用Identity增删改查用户介绍 10-24
- C语言中atoi函数模拟实现介绍 10-18