您现在的位置是:群英 > 开发技术 > web开发
MVC之如何利用在mvcpager控件中实现分页
Admin发表于 2022-05-26 17:13:20686 次浏览
这篇文章给大家分享的是“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())
            {
                iqueryable<userinfo> p = from c in db.userinfo
                                         select new userinfo { customerid = c.customerid, customername = c.customername, telephone = c.telephone, pid = c.pid, address = c.address };
                pagedlist<userinfo> 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控件中实现分页已经有了进一步的了解,如果想要了解更多相关的内容,欢迎关注群英网络,群英网络将为大家推送更多相关知识点的文章。

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。

相关信息推荐
2022-06-02 17:20:45 
摘要:php数组相加不会合并重复值。php中可使用“+”运算符将一个或多个数组相加起来,会合并这些数组返回一个新数组,语法“数组1+数组2+..”,后面数组的元素会追加到第一个元素的末尾,值是否重复没有影响;但键名重复,则前面元素会覆盖后面元素。
2022-08-27 17:03:50 
摘要:本篇文章给大家带来了关于javascript的相关知识,主要介绍了JavaScript ECMAScript 6(ES2015~ES2022)所有新特性总结,文章围绕主题展开详细的内容介绍,具有一定的参考价值,下面一起来看一下,希望对大家有帮助。
2022-07-15 17:55:05 
摘要:本篇文章给大家介绍一下Bootstrap3和Bootstrap4的垂直水平居中。有一定的参考价值,有需要的朋友可以参考一下,希望对大家有所帮助。
云活动
推荐内容
热门关键词
热门信息
群英网络助力开启安全的云计算之旅
立即注册,领取新人大礼包
  • 联系我们
  • 24小时售后:4006784567
  • 24小时TEL :0668-2555666
  • 售前咨询TEL:400-678-4567

  • 官方微信

    官方微信
Copyright  ©  QY  Network  Company  Ltd. All  Rights  Reserved. 2003-2019  群英网络  版权所有   茂名市群英网络有限公司
增值电信经营许可证 : B1.B2-20140078   粤ICP备09006778号
免费拨打  400-678-4567
免费拨打  400-678-4567 免费拨打 400-678-4567 或 0668-2555555
微信公众号
返回顶部
返回顶部 返回顶部