官方地址参考http://www.jquery-bootgrid.com/Examples

Bootgrid 是一款基于BootStrap 开发的带有查询,分页功能的列表显示组件。可以在像MVC中开发快速搭建信息展示列表。我在开发过程中碰到很多问题,在此总结一下。由于是基于Bootstrap开发的,在使用之前先导入与之相关的Jquery,CSS相关文件,然后导入Bootgrid的脚本与样式。

前端

<table id="grid-data" class="table table-bordered table-hover">
  <thead>
    <tr>
      <th data-column-id="UserName">@Html.LabelFor(m => m.UserName)</th>
      <th data-column-id="UserPhone">@Html.LabelFor(m => m.UserPhone)</th>
      <th data-column-id="CrateTime" data-order="desc">@Html.LabelFor(m => m.CrateTime)</th>
      <th data-column-id="link" data-formatter="commands" data-sortable="false">详细</th>
    </tr>
  </thead>
</table>

说明:该组件通过请求接收形如{"current":1,"rowCount":10,"total":2,"rows":[{"UserName":"swt","UserPhone":"1","CrateTime":"20151203"}]}的json数据格式。 data-column-id与返回的json中的Id互相对应。data-order当前列的排序方式, data-sortable=false 当前不排序

$("#grid-data").bootgrid({
  ajax: true, //是否发生异步请求
  url: "../UserCenter/Result", //请求的Url  返回json格式数据
  formatters: {
    "commands": function (column, row) { //commands 参考上面 data-formatter="commands"  与前面一致即可

    return "<a href=\"#\" class=\"command-detail\" data-row-id=\"" + row.UserId + "\">详细</a>&nbsp;" +
        "<a href=\"#\" class=\"command-edit\" data-row-id=\"" + row.UserId + "\">编辑</a>&nbsp;" +
        "<a href=\"#\" class=\"command-delete\" data-row-id=\"" + row.UserId + "\">删除</a>&nbsp;";
            }
        }
    }).on("loaded.rs.jquery.bootgrid", function () {
    /* Executes after data is loaded and rendered */
    grid.find(".command-detail").on("click", function (e) {
      $("#detail-mod").removeData("bs.modal");
      $("#detail-mod").modal({
        remote: "../UserCenter/UserDetail?type=detail&userId=" + $(this).data("row-id") + "" //点击详细按钮时请求路径
        });
      }).end().find(".command-edit").on("click", function (e) {
    $("#detail-mod").removeData("bs.modal");//为了模态窗口加载时 移除之前的数据,否则,一直保留第一次的数据(个人认为)
    $("#detail-mod").modal({
      //实现
      });
    }).end().find(".command-delete").on("click", function (e) {

      //实现

      });
    });
  });

还有关于BootStrap 弹出模态窗口 加载动态数据

在主页面中添加如下

<div class="modal fade" id="detail-mod">
  <div class="modal-dialog" style="height: 700px ;width:900px">
    <div class="modal-content" id="detail-content">
    </div>
  </div>
</div>

在Mvc partial视图中添加

<div class="modal-header">
  <button type="button" class="close" data-dismiss="modal">
    <span>&times;</span>
  </button>
  <h4 class="modal-title">模态窗口标题</h4>
</div>
<div class="modal-body">
  //数据展示部分。
</div>

在主页面中通过remote 属性获取即可。

Mvc 项目中使用Bootstrap以及基于bootstrap的 Bootgrid的更多相关文章

  1. 转 mvc项目中,解决引用jquery文件后智能提示失效的办法

    mvc项目中,解决用Url.Content方法引用jquery文件后智能提示失效的办法   这个标题不知道要怎么写才好, 但是希望文章的内容对大家有帮助. 场景如下: 我们在用开发开发程序的时候,经常 ...

  2. 谈谈MVC项目中的缓存功能设计的相关问题

    本文收集一些关于项目中为什么需要使用缓存功能,以及怎么使用等,在实际开发中对缓存的设计的考虑 为什么需要讨论缓存呢? 缓存是一个中大型系统所必须考虑的问题.为了避免每次请求都去访问后台的资源(例如数据 ...

  3. 在 ASP.NET MVC 项目中使用 WebForm、 HTML

    原文地址:http://www.cnblogs.com/snowdream/archive/2009/04/17/winforms-in-mvc.html ASP.NET MVC和WebForm各有各 ...

  4. MVC项目中如何判断用户是在用什么设备进行访问

    使用UAParser在C#MVC项目中如何判断用户是在用什么设备进行访问(手机,平板还是普通的电脑) 现在我们开发的很多web应用都要支持手机等移动设备.为了让手机用户能有更加好的用户体验,我们经常为 ...

  5. 在已有的Asp.net MVC项目中引入Taurus.MVC

    Taurus.MVC是一个优秀的框架,如果要应用到已有的Asp.net MVC项目中,需要修改一下. 1.前提约定: 走Taurus.MVC必须指定后缀.如.api 2.原项目修改如下: web.co ...

  6. ASP.NET MVC项目中App_Code目录在程序应用

    学习ASP.NET MVC,如果你是开发ASP.NET MVC项目的,也许你去为项目添加前ASP.NET项目的APP_Code目录,在这里创建与添加的Class类,也许你无法在MVC项目所引用. 那这 ...

  7. 如何在mvc项目中使用apiController

    文章地址:How do you route from an MVC project to an MVC ApiController in another project? 文章地址:How to Us ...

  8. 在ASP.NET MVC项目中使用极验验证(geetest)

    时间 2016-03-02 18:22:37 smallerpig 原文  http://www.smallerpig.com/979.html 主题 ASP.NET MVC   geetest开发体 ...

  9. 添加Bootstrap 到MVC项目中(vs2010)

    环境:Visual Studio 2010   ASP.NET MVC3 手动添加: 下载地址:http://twitter.github.com/bootstrap/ 一个js,两个css,两张图 ...

随机推荐

  1. RHCE7 学习里程-2.telnet 服务配置

    一.安装telnet 服务 1.yum install -y telnet-server 2.yum install -y xinetd 安装两个包 将两个服务做成开机启动 1.systemctl e ...

  2. c++ 字符检测 TCharacter

    c++ 字符检测 IsSurrogatePair,IsHighSurrogate,IsLowSurrogate,ConvertToUtf32http://docwiki.embarcadero.com ...

  3. 使用json格式去call外部系统

    1. 使用postman去call post方式 body填入对应的json请求 格式选json 2. 使用java 代码去call import java.io.BufferedReader; im ...

  4. e s6 知识点

    http://es6.ruanyifeng.com/#docs/reflect 1.资料对es6箭头函数中的this总结:箭头函数中的this指向的是 定义时的this,而不是 执行时的this.

  5. 【转】内存耗用:VSS/RSS/PSS/USS

    Terms VSS- Virtual Set Size 虚拟耗用内存(包含共享库占用的内存) RSS- Resident Set Size 实际使用物理内存(包含共享库占用的内存) PSS- Prop ...

  6. Pycharm 激活码 2019年1月9日16:57:13

    K03CHKJCFT-eyJsaWNlbnNlSWQiOiJLMDNDSEtKQ0ZUIiwibGljZW5zZWVOYW1lIjoibnNzIDEwMDEiLCJhc3NpZ25lZU5hbWUiO ...

  7. js产生对象的3种基本方式(工厂模式,构造函数模式,原型模式)

    1.工厂模式 function a(name){ var b = new object(); b.name = name; b.say = function(){ alert(this.name); ...

  8. 从零开始搭建k8s-20180301

    yum install -y yum-utils git etcd yum-config-manager --add-repo https://download.docker.com/linux/ce ...

  9. 创建数据库sql语句

    create database JXGL; go create table S( sno char(10)primary key not null, sname nvarchar(10) not nu ...

  10. tftp-hpa客户端使用说明

    1.板子 sudo apt-get install tftp-hpa 2.主机chmod 777 tftp—dir 3.tftp -4 192.168.1.122 -c put lib2.tar.gz ...