c# mvc webGrid 无刷新分页「建议收藏」

c# mvc webGrid 无刷新分页「建议收藏」参考地址:http://www.dotnetcurry.com/ShowArticle.aspx?ID=618一、webGrid.css.webGrid{margin:4px;border-collapse:collapse;/*width:300px;*/}.header{background-color:#E8E8E8;font-weight:bold;color:#FFF;}.head{

大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。

Jetbrains全系列IDE稳定放心使用

参考地址:http://www.dotnetcurry.com/ShowArticle.aspx?ID=618

一、webGrid.css
.webGrid
{

    margin: 4px;
    border-collapse: collapse; /*width: 300px;*/
}
.header
{

    background-color: #E8E8E8;
    font-weight: bold;
    color: #FFF;
}
.head
{

    background-color: #E8E8E8;
    font-weight: bold;
    color:Black;
}

.webGrid th, .webGrid td
{

    width: 190px;
    #width:170px;
    border: 1px solid #C0C0C0;
    padding: 5px;
}
.alt
{

    background-color: #E8E8E8;
    color: #000;
}
.person
{

    width: 200px;
    font-weight: bold;
}

二、Pager.js
var sPath = “”;
$(function () {

    if ($(“#EfficientPaging”) != undefined) {

        sPath = $(“#EfficientPaging”).val();
        $.getJSON(sPath, null, function (d) {

            // add the dynamic WebGrid to the body
            $(“#xwGrid”).append(d.Data);

            // create the footer
            var footer = createFooter(d.Count);

            $(“#DataTable tfoot a”).live(“click”, function (e) {

                e.preventDefault();
                var data = {

                    page: $(this).text()
                };

                $.getJSON(sPath, data, function (html) {

                    // add the data to the table   
                    $(“#DataTable”).remove();
                    $(“body”).append(html.Data);

                    // re-add the footer
                    $(‘#DataTable thead’).after(footer);
                });
            });
        });
    }
});

function createFooter(d) {

    var rowsPerPage = 5;
    var footer = “<tfoot><tr><td style=’border:none’>”;
    for (var i = 1; i < (d + 1); i++) {

        footer = footer + “<a href=#>” + i + “</a>&nbsp;”;
    }
    footer = footer + “</td></tr></tfoot>”;
    $(“#DataTable thead”).after(footer);
    return footer;
}  
三、view
 <link href=”../../Content/css/webGrid.css” rel=”stylesheet” type=”text/css” />
 <script src=”../../Content/jquery/mvcPager/Pager.js” type=”text/javascript”></script>

<input id=”EfficientPaging” name=”EfficientPaging” type=”hidden” value=”/Seller/EfficientPaging” />
    <div id=”xwGrid”>
    </div>
四、Controller
public class SellerController : Controller
{

 private List<Seller> sellPopular;
 [HttpGet]
        public JsonResult EfficientPaging(int? page)
        {

            int icount =10;//每页显示数量

            int skip = page.HasValue ? page.Value – 1 : 0;  //如果page为0默认显示第一页
            sellPopular = SellerAccess.GetSellerList(skip, icount);    //获取当前页显示的数据
            var grid = new WebGrid(sellPopular);
            var htmlString = grid.GetHtml(
               tableStyle: “webGrid”,
               headerStyle: “head”,
               alternatingRowStyle: “alt”,
               columns: grid.Columns(
               grid.Column(“SellerID”, “商家编号”, canSort: false),
               grid.Column(“SellerNick”, “商家昵称”,canSort:false),
                  grid.Column(format: (item) => {

                      return new HtmlString(“<input type=’button’οnclick=’RedirectVersion(” + item[“SellerID”] + “)’ value=’管理版本’/>&nbsp;<input type=’button’ οnclick=’UpSeller(” + item[“SellerID”] + “)’ value=’修改’/>&nbsp;<input type=’button’ value=’删除’οnclick=’DeleteSeller(” + item[“SellerID”] + “)'”);
                  }, columnName: “操作”,canSort:false)
                  ),
                  htmlAttributes: new { id = “DataTable” }
              );
           
            int sellerCount = SellerAccess.GetSellerCount();
            return Json(new
            {

               
                Data = htmlString.ToHtmlString(),
                Count = Math.Ceiling((double)sellerCount/(double)icount)    //计算总页数s
            }, JsonRequestBehavior.AllowGet);
        }
}
五、DataAccess
 /// <summary>
        /// 查询所有商家总数

        /// </summary>
        /// <returns></returns>
        public static int GetSellerCount()
        {

            int sellerCount = 0;
            using (ShopexMobileEntities db = new ShopexMobileEntities())
            {

                try
                {

                   sellerCount=db.Seller.ToList().Count();
                }
                catch (Exception)
                {

                    db.Dispose();
                    return sellerCount;
                }
            }
            return sellerCount;
        }
        /// <summary>
        /// 获取当前页显示的数据
        /// </summary>
        /// <param name=”pageIndex”>当前页</param>
        /// <param name=”count”>每页显示的数量</param>
        /// <returns></returns>
        public static List<Seller> GetSellerList(int pageIndex, int count)
        {

            List<Seller> sellerList = new List<Seller>();
            using (ShopexMobileEntities db = new ShopexMobileEntities())
            {

                try
                {

                     sellerList=db.Seller.OrderBy(o => o.SellerID).Skip(pageIndex * count).Take(count).ToList();
                  
                }
                catch (Exception)
                {

                    db.Dispose();
                    return null;
                }
            }
            return sellerList;
        }

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/185643.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • rpm 安装冲突「建议收藏」

    rpm 安装冲突「建议收藏」1.要安装的包比已安装的包旧,则采用降级的方式安装 rpm -Uvhkpartx-0.4.9-72.el6.x86_64.rpm –oldpackage 2.安装的包比已安装的包新,则直接升级即可 rpm -Uvhkpartx-0.4.9-72.el6.x86_64.rpm  或者末尾追加 –replacefiles  或  –repl…

    2022年5月5日
    37
  • 【算法】java 实现数组的反转

    【算法】java 实现数组的反转数组的反转原理跟冒泡排序有点像,都是通过交换位置,只不过数组的反转是交换第一个和最后一个的位置,第二个和倒数第二个的位置,冒泡排序是交互相邻两个的位置.下面看一下具体的代码实现packagetest;/***数组的反转*/publicclassTestDemo{publicstaticvoidmain(String[]args){…

    2022年5月27日
    42
  • linux ghost备份_pe备份linux系统

    linux ghost备份_pe备份linux系统Windows系统备份可以用ghost工具软件完成,Linux系统不能完全依赖于ghost工具,一则是ghost本身是有版权的软件,二则ghost只支持ext2、ext3文件系统的Linux分区,不支持reiserfs、xfs等比较高级的文件系统,ghost本身并不备份mbr,因此常造成恢复后的系统grub出错的问题。  linux本身自带有着优秀的备份工具,传统如:tar、cpio、dd,新的有

    2025年8月29日
    7
  • 中国软件开发外包公司排名-国内最大的软件开发商有哪些呢

    中国软件开发外包公司排名-国内最大的软件开发商有哪些呢中国软件开发外包公司排名-国内最大的软件开发商有哪些呢

    2022年6月5日
    31
  • 符号_王者荣耀2019名字特殊符号大全 最好看的特殊符号复制[通俗易懂]

    符号_王者荣耀2019名字特殊符号大全 最好看的特殊符号复制[通俗易懂][海峡网]大家玩王者荣耀的时候都会取一个特别的名字,如果再加上特殊符号的话,会让人更印象深刻,也比较容易交上朋友,那么2019年哪些特殊符号可以用在游戏中,一起来了解一下吧。【王者荣耀特殊符号推荐2019】1、爱心符号:დღ♡❣❤❥❦❧♥2、音符符号:♩♪♫♬♭♮♯3、文化符号:☠☤☥☦☧☨☩☪☫☬☮☭☯☸☽☾♕♚♛✙✚✛✜…

    2022年6月1日
    36
  • mysql不执行命令_linux mysql启动命令

    mysql不执行命令_linux mysql启动命令Linux下使用mysql命令需要配置好环境以及各种文件,下面由学习啦小编为大家整理了linux下mysql命令不能用的相关知识,希望对大家有帮助!linux的mysql命令没用解决方法1.重新安装mysql命令,方法步骤如下:一安装步骤从这里下载你需要的版本(注意选择你操作系统是64位的还是32位的):这里只介绍两种判断linux是64位还是32的方法:命令:file/bin/cat[roo…

    2022年9月16日
    2

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号