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)
上一篇 2022年10月5日 下午4:00
下一篇 2022年10月5日 下午4:16


相关推荐

  • linux 中文 文件名乱码,中文文件名乱码问题

    linux 中文 文件名乱码,中文文件名乱码问题出自 LinuxWiki 提示 此文已超过 5 年 1880 天 未更新 如发现内容过时或有误 欢迎改进 注意 本文解决的是文件名或文件夹名的编码问题 要查看转换文件内容的选项 请参考 iconv 工具 更多与乱码有关的问题 请参阅中文编码与乱码问题分类 中文文件名乱码产生的原因有二 一是挂载 NTFS 或 FAT 文件系统时 编码指定不正确导致乱码 或问号 二是在文件系统中文件名存储的编码不正确 导致乱码

    2026年3月26日
    2
  • landset8各波段_landsat8波段

    landset8各波段_landsat8波段Landsat8的不同波段组合说明(2013-08-0811:32:56)转载▼标签:landsat8oli陆地成像仪杂谈分类:遥感技术LandsatTM(ETM+)7个波段可以组合很多RGB方案用于不同地物的解译,Landsat8的OLI陆地成像仪包括9个波段,可以组合更多的RGB方案。OLI包括了ETM+传感器所有的波段,为了避免大气吸收特征,OLI对波段进行了重新调整,比较大的调整是OL…

    2022年7月23日
    9
  • 25个国外优秀的餐饮网站设计作品欣赏

    25个国外优秀的餐饮网站设计作品欣赏25 个国外优秀的餐饮网站设计作品欣赏 这篇文章收集了 25 个国外优秀的餐饮网站设计作品 希望能带给你灵感 很多餐饮店都会建立自己网站 提供在线订餐服务 这些通常会搭配诱人的食物图片 吸引顾客订购 一起欣赏 McDonald sRubyTuesday

    2026年3月16日
    2
  • DeepSeek+Kimi生成PPT[源码]

    DeepSeek+Kimi生成PPT[源码]

    2026年3月12日
    2
  • CentOS7安装Jenkins教程

    CentOS7安装Jenkins教程1.下载JenkinsJenkins下载地址:http://jenkins-ci.org/2.安装jenkins1.卸载旧jenkinsrpm-qa|grepjenkins2.卸载jenkinsrpm-e–nodepsjenkins3.彻底删除jenkins残留文件find/-inamejenkins|xargs-n1000rm-r…

    2022年5月14日
    38
  • linux-kernel(内核)升级,降级与使用

    linux-kernel(内核)升级,降级与使用linux-kernel(内核)升级,降级与使用

    2022年4月24日
    54

发表回复

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

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