public ActionResult Index()
{
OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["connstr"].ToString());
conn.Open();
DataTable datatable = new DataTable();
OleDbCommand comm = new OleDbCommand("select * from UserList",conn);
OleDbDataAdapter dar = new OleDbDataAdapter(comm);
dar.Fill(datatable);
conn.Close();
conn.Dispose();
///////////////////////////
List<Model.UserList> list_m = new List<UserList>();
list_m = (List<Model.UserList>)Model.ModelConvertHelper<Model.UserList>.ConvertToModel(datatable);
PagedList<UserList> list_m_P =这个地方不知道怎么写,因为数据源是list<T>,不是linq出来的
return View(list_m_P);
}
/**************************************************************************************************************/ /***************************************************分页插件*************************************************/ /* *参数说明 *options.recordCount 总数 *options.pageSize 每页大小 *options.pagenumber 当前页数 *options.customerText 是否自定义文本,默认不显示 *options.buttonClickCallback 分页的回调函数 * 用法 :$("#mypager").pager({ pagenumber: pageclickednumber, recordCount: recordCount, pageSize: pageSize,cKey:value, buttonClickCallback: PageClick}) */ ; (function ($) { $.fn.pager = function (options) { var opts = $.extend({}, $.fn.pager.defaults, options); var pagecount = GetPageCount(parseInt(opts.recordCount), parseInt(opts.pageSize)); opts.pagecount = pagecount; $(this).empty(); $(this).append(renderpager(parseInt(opts.pagenumber), pagecount, parseInt(opts.pageSize), parseInt(opts.recordCount), opts.customerText, opts.buttonClickCallback)); if (opts.buttonClickCallback != undefined && opts.buttonClickCallback != null) { $(".pager_items").children("li").click(function () { var data = $(this).attr("data"); if (data > 0) { opts.buttonClickCallback(data, opts.pageSize); } }); $(".pageselectpage").change(function () { var size = $(this).val(); opts.buttonClickCallback(1, size); }); } }; //获得总页数 function GetPageCount(recordCount, pageSize) { if (recordCount <= 0) return 1; if (recordCount % pageSize == 0) return parseInt(recordCount / pageSize); else return parseInt(recordCount / pageSize) + 1; } //pagenumber function renderpager(pagenumber, pagecount, pageSize, recordCount, customerText, buttonClickCallback) { var items = [1, 2, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50]; var $pager = ""; $pager += "<div class=\"paget\">"; //$pager += "<div class=\"dataTables_info\">当前页 " + pagenumber + " / " + pagecount + " 共 " + recordCount + " 行 ,每页"; $pager += "<div class=\"dataTables_info\">共 " + recordCount + " 行 ,每页"; $pager += "<select class=\"input-small pageselectpage\" style='width:60px;'>"; for (var i = 0; i < items.length; i++) { if (items[i] == pageSize) { $pager += "<option selected=\"selected\" value=\"" + items[i] + "\">" + items[i] + "</option>"; } else { $pager += "<option value=\"" + items[i] + "\">" + items[i] + "</option>"; } } $pager += "</select>行</div>"; $pager += "</div>"; $pager += "<div class=\"pagen\">"; $pager += "<div class=\"dataTables_paginate paging_bootstrap pagination\">"; $pager += "<ul class='pager_items'>"; if (pagenumber <= 1) { $pager += "<li class=\"prev disabled\" data=\"1\"><a href=\"javascript:void(0)\">首页</a></li>"; } else { $pager += "<li class=\"prev\" data=\"1\"><a href=\"javascript:void(0)\">首页</a></li>"; } var start = pagenumber - 3; start = start <= 1 ? 1 : start; if (start > 1) { $pager += "<li data=\"0\"><a href=\"javascript:void(0)\">...</a></li>"; } for (var i = start; i < pagenumber; i++) { $pager += "<li data=\"" + i + "\"><a href=\"javascript:void(0)\">" + i + "</a></li>"; } $pager += "<li class=\"active\" data=\"" + pagenumber + "\"><a href=\"javascript:void(0)\">" + pagenumber + "</a></li>"; var end = pagenumber + 3; end = end >= pagecount ? pagecount : end; for (var i = pagenumber + 1; i <= end; i++) { $pager += "<li data=\"" + i + "\"><a href=\"javascript:void(0)\">" + i + "</a></li>"; } if (pagecount > end) { $pager += "<li data=\"0\"><a href=\"javascript:void(0)\">...</a></li>"; } if (pagenumber >= pagecount) { $pager += "<li class=\"next disabled\" data=\"" + pagecount + "\"><a href=\"javascript:void(0)\">尾页</a></li>"; } else { $pager += "<li class=\"next\" data=\"" + pagecount + "\"><a href=\"javascript:void(0)\">尾页</a></li>"; } $pager += "</ul>"; $pager += "</div>"; $pager += "</div>"; return $pager; } function GetPageNum() { alert("请输入要跳转的页码!"); } $.fn.pager.defaults = { pagenumber: 1, pagecount: 1, recordCount: 100, pageSize: 10 }; })(jQuery);
public ActionResult Index()
{
OleDbConnection conn = new OleDbConnection(ConfigurationManager.ConnectionStrings["connstr"].ToString());
conn.Open();
DataTable datatable = new DataTable();
OleDbCommand comm = new OleDbCommand("select * from UserList",conn);
OleDbDataAdapter dar = new OleDbDataAdapter(comm);
dar.Fill(datatable);
conn.Close();
conn.Dispose();
///////////////////////////
List<Model.UserList> list_m = new List<UserList>();
list_m = (List<Model.UserList>)Model.ModelConvertHelper<Model.UserList>.ConvertToModel(datatable);
PagedList<UserList> list_m_P =这个地方不知道怎么写,因为数据源是list<T>,不是linq出来的
return View(list_m_P);
}
翻页和MVC有关系吗?
翻页和你用什么Web框架没有直接关系,这里估计你关心的无非是两点:分页的数据和前端的展示:
1、分页的数据提取,如果你自己写的话,用ASP.NET MVC默认搭配的EF,查询时lambda表达式的Skip和Take两个方法搭配能够满足基本需要,自己写SQL或者其他ORM原理一致。推荐搜索下“MVC分页控件”,有很多网友开发的服务端控件可用。
2、页面上分页导航的展示部分,上述服务端分页控件一般都提供该功能。当然,有了数据源,也可以自己写,也有不少JS的插件可以选择。
可参考:
http://www.webdiyer.com/mvcpager/
http://www.cnblogs.com/longgel/archive/2010/05/03/1726415.html
http://www.cnblogs.com/lhb25/archive/2012/08/08/ajax-jquery-pagination-plugin-tutorial.html
MVCpagerhttp://www.webdiyer.com/mvcpager/
jquery.pagination.jshttp://www.cnblogs.com/ChangeNow/p/3613667.html都可以实现分页
我是自己写了一个方法来输出页码标签