MVC之如何利用在mvcpager控件中实现分页
导读:这篇文章给大家分享的是“MVC之如何利用在mvcpager控件中实现分页”,文中的讲解内容简单清晰,对大家认识和了解都有一定的帮助,对此感兴趣的朋友,接下来就跟随小编一起了解一下“MVC之如何利用在mvcpager控件中实现分页”吧。...
这篇文章给大家分享的是“MVC之如何利用在mvcpager控件中实现分页”,文中的讲解内容简单清晰,对大家认识和了解都有一定的帮助,对此感兴趣的朋友,接下来就跟随小编一起了解一下“MVC之如何利用在mvcpager控件中实现分页”吧。本文实例为大家分享了mvc使用mvcpager实现分页效果的具体代码,供大家参考,具体内容如下
一、数据库表
use [studentdb] go /****** object: table [dbo].[userinfo] script date: 07/27/2018 13:59:03 ******/ set ansi_nulls on go set quoted_identifier on go set ansi_padding on go create table [dbo].[userinfo]( [customerid] [int] identity(1,1) not null, [customername] [varchar](50) not null, [pid] [varchar](50) not null, [telephone] [varchar](50) not null, [address] [varchar](20) null, primary key clustered ( [customerid] asc )with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary], constraint [uq_pid] unique nonclustered ( [pid] asc )with (pad_index = off, statistics_norecompute = off, ignore_dup_key = off, allow_row_locks = on, allow_page_locks = on) on [primary] ) on [primary] go set ansi_padding off go alter table [dbo].[userinfo] with check add constraint [ck_pid] check ((len([pid])=(15) or len([pid])=(18))) go alter table [dbo].[userinfo] check constraint [ck_pid] go alter table [dbo].[userinfo] with check add constraint [ck_telephone] check ((len([telephone])=(11))) go alter table [dbo].[userinfo] check constraint [ck_telephone] go
二、建立linq
三、在model创建userinfo
using system;
using system.collections.generic;
using system.linq;
using system.web;
namespace web.models
{
public class userinfo
{
private int customerid;
public int customerid
{
get {
return customerid;
}
set {
customerid = value;
}
}
private string customername;
public string customername
{
get {
return customername;
}
set {
customername = value;
}
}
private string pid;
public string pid
{
get {
return pid;
}
set {
pid = value;
}
}
private string telephone;
public string telephone
{
get {
return telephone;
}
set {
telephone = value;
}
}
private string address;
public string address
{
get {
return address;
}
set {
address = value;
}
}
}
}
四、在controllers创建home控制器
添加mvcpager.dll,并引用mvcpager的命名空间webdiyer.webcontrols.mvc。
using system;
using system.collections.generic;
using system.linq;
using system.web;
using system.web.mvc;
using web.models;
using webdiyer.webcontrols.mvc;
namespace web.controllers
{
public class homecontroller : controller
{
//
// get: /page/
//默认分页
private const int defaultpagesize = 5;
//
public actionresult index(int? id)
{
using (dbdatacontext db = new dbdatacontext())
{
iqueryableuserinfo>
p = from c in db.userinfo
select new userinfo {
customerid = c.customerid, customername = c.customername, telephone = c.telephone, pid = c.pid, address = c.address }
;
pagedlistuserinfo>
m = p.topagedlist(id ?? 1, defaultpagesize);
return view(m);
}
}
}
}
五、添加视图index
fo>
>
" %>
%@ import namespace="web.models" %>
%@ import namespace="webdiyer.webcontrols.mvc" %>
!doctype html>
html>
head runat="server">
meta name="viewport" content="width=device-width" />
title>
index/title>
%--样式表--%>
link href="../../content/site.css" rel="stylesheet" type="text/css" />
script src="../../scripts/jquery-1.8.2.min.js" type="text/javascript">
/script>
/head>
body>
div class="divfloat">
div id="divpages">
table>
tr>
th>
编号
/th>
th>
姓名
/th>
th>
身份证号
/th>
th>
电话号码
/th>
th>
地址
/th>
/tr>
%foreach (userinfo od in model)
{
%>
tr>
td>
%=od.customerid.tostring() %>
/td>
td>
%=od.customername.tostring() %>
/td>
td>
%=od.pid.tostring() %>
/td>
td>
%=od.telephone.tostring() %>
/td>
td>
%=od.address.tostring() %>
/td>
/tr>
%
}
%>
/table>
new ajaxoptions() {
updatetargetid = "divpages" }
)%>
--%>
%=html.pager(model, new pageroptions
{
pageindexparametername = "id",
cssclass = "pages",
firstpagetext = "首页",
lastpagetext = "末页",
prevpagetext = "上一页",
nextpagetext = "下一页",
currentpageritemwrapperformatstring = "span class=\"cpb\">
{
0}
/span>
",
showpageindexbox = true,
numericpageritemwrapperformatstring = "span class=\"item\">
{
0}
/span>
",
pageindexboxtype = pageindexboxtype.dropdownlist,
showgobutton = false,pageindexboxwrapperformatstring=" 转到{
0}
",separatorhtml = "" }
)%>
/div>
/div>
/body>
/html>
感谢各位的阅读,以上就是“MVC之如何利用在mvcpager控件中实现分页”的内容了,通过以上内容的阐述,相信大家对MVC之如何利用在mvcpager控件中实现分页已经有了进一步的了解,如果想要了解更多相关的内容,欢迎关注网络,网络将为大家推送更多相关知识点的文章。
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: MVC之如何利用在mvcpager控件中实现分页
本文地址: https://pptw.com/jishu/654406.html
