Bootstrap table: http://bootstrap-table.wenzhixin.net.cn/zh-cn/getting-started/

1. 控制器代码:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6.  
  7. namespace AspDotNetMVCBootstrapTable.Controllers
  8. {
  9. public class HomeController : Controller
  10. {
  11. public ActionResult Index()
  12. {
  13. return View();
  14. }
  15.  
  16. public JsonResult GetData()
  17. {
  18. var products = new[] {
  19. new Product { ID = "", Name = "Item 1", Price = "$1" },
  20. new Product { ID = "", Name = "Item 2", Price = "$1" },
  21. new Product { ID = "", Name = "Item 3", Price = "$1" },
  22. new Product { ID = "", Name = "Item 4", Price = "$4" },
  23. new Product { ID = "", Name = "Item 5", Price = "$5" },
  24. new Product { ID = "", Name = "Item 6", Price = "$6" },
  25. new Product { ID = "", Name = "Item 7", Price = "$7" },
  26. new Product { ID = "", Name = "Item 8", Price = "$8" },
  27. new Product { ID = "", Name = "Item 9", Price = "$9" },
  28. new Product { ID = "", Name = "Item 10", Price = "$10" },
  29. new Product { ID = "", Name = "Item 11", Price = "$11" },
  30. new Product { ID = "", Name = "Item 12", Price = "$12" },
  31. new Product { ID = "", Name = "Item 13", Price = "$13" },
  32. new Product { ID = "", Name = "Item 14", Price = "$14" },
  33. new Product { ID = "", Name = "Item 15", Price = "$15" },
  34. new Product { ID = "", Name = "Item 16", Price = "$16" },
  35. new Product { ID = "", Name = "Item 17", Price = "$17" },
  36. new Product { ID = "", Name = "Item 18", Price = "$18" },
  37. new Product { ID = "", Name = "Item 19", Price = "$19" },
  38. new Product { ID = "", Name = "Item 20", Price = "$20" },
  39. new Product { ID = "", Name = "Item 21", Price = "$21" },
  40. new Product { ID = "", Name = "Item 22", Price = "$22" },
  41. new Product { ID = "", Name = "Item 23", Price = "$23" },
  42. new Product { ID = "", Name = "Item 24", Price = "$24" },
  43. new Product { ID = "", Name = "Item 25", Price = "$25" },
  44. new Product { ID = "", Name = "Item 26", Price = "$26" },
  45. new Product { ID = "", Name = "Item 27", Price = "$27" },
  46. new Product { ID = "", Name = "Item 28", Price = "$28" },
  47. new Product { ID = "", Name = "Item 29", Price = "$29" },
  48. new Product { ID = "", Name = "Item 30", Price = "$30" },
  49. };
  50.  
  51. return Json(products.ToList(), JsonRequestBehavior.AllowGet);
  52.  
  53. }
  54.  
  55. public ActionResult About()
  56. {
  57. ViewBag.Message = "Your application description page.";
  58.  
  59. return View();
  60. }
  61.  
  62. public ActionResult Contact()
  63. {
  64. ViewBag.Message = "Your contact page.";
  65.  
  66. return View();
  67. }
  68.  
  69. private class Product
  70. {
  71. public string ID { get; set; }
  72. public string Name { get; set; }
  73. public string Price { get; set; }
  74. }
  75.  
  76. }
  77. }

2. 视图代码:

  1. @{
  2. ViewBag.Title = "Home Page";
  3. }
  4. @section css {
  5. <link href="~/Scripts/Bootstrap-Table-1.5.0/bootstrap-table.min.css" rel="stylesheet" />
  6. <style type="text/css">
  7.  
  8. </style>
  9. }
  10. <div class="row">
  11. <div class="col-md-12">
  12. <h2>ASP.NET MVC and Bootstrap Table Integration</h2>
  13. <table id="table-javascript"></table>
  14. </div>
  15. </div>
  16. @section Scripts {
  17. <script src="~/Scripts/Bootstrap-Table-1.5.0/bootstrap-table.min.js"></script>
  18. <script src="~/Scripts/Bootstrap-Table-1.5.0/locale/bootstrap-table-en-US.min.js"></script>
  19. <script type="text/javascript">
  20. $(function () {
  21. $('#table-javascript').bootstrapTable({
  22. method: 'get',
  23. url: '/Home/GetData',
  24. cache: false,
  25. height: ,
  26. striped: true,
  27. pagination: true,
  28. pageSize: ,
  29. pageList: [, , , , ],
  30. search: true,
  31. showColumns: true,
  32. showRefresh: true,
  33. minimumCountColumns: ,
  34. clickToSelect: true,
  35. columns: [{
  36. field: 'state',
  37. checkbox: true
  38. }, {
  39. field: 'ID',
  40. title: 'Item ID',
  41. align: 'right',
  42. valign: 'bottom',
  43. sortable: true
  44. }, {
  45. field: 'Name',
  46. title: 'Item Name',
  47. align: 'center',
  48. valign: 'middle',
  49. sortable: true
  50. }, {
  51. field: 'Price',
  52. title: 'Item Price',
  53. align: 'left',
  54. valign: 'top',
  55. sortable: true
  56. }, {
  57. field: 'operate',
  58. title: 'Item Operate',
  59. align: 'center',
  60. valign: 'middle',
  61. clickToSelect: false,
  62. formatter: operateFormatter,
  63. events: operateEvents
  64. }]
  65. });
  66.  
  67. });
  68.  
  69. function operateFormatter(value, row, index) {
  70. return [
  71. '<a class="like" href="javascript:void(0)" title="Like">',
  72. '<i class="glyphicon glyphicon-heart"></i>',
  73. '</a>',
  74. ' <a class="edit ml10" href="javascript:void(0)" title="Edit">',
  75. '<i class="glyphicon glyphicon-edit"></i>',
  76. '</a>',
  77. ' <a class="remove ml10" href="javascript:void(0)" title="Remove">',
  78. '<i class="glyphicon glyphicon-remove"></i>',
  79. '</a>'
  80. ].join('');
  81. }
  82.  
  83. window.operateEvents = {
  84. 'click .like': function (e, value, row, index) {
  85. alert('You click like icon, row: ' + JSON.stringify(row));
  86. console.log(value, row, index);
  87. },
  88. 'click .edit': function (e, value, row, index) {
  89. alert('You click edit icon, row: ' + JSON.stringify(row));
  90. console.log(value, row, index);
  91. },
  92. 'click .remove': function (e, value, row, index) {
  93. alert('You click remove icon, row: ' + JSON.stringify(row));
  94. console.log(value, row, index);
  95. }
  96. };
  97.  
  98. </script>
  99. }

项目代码查看地址: http://mvcbootstraptable.codeplex.com/

另: MVC中对Bootstrap的封装: http://mvc4bootstaphelper.codeplex.com/ (感觉一般用不到)

在ASP.NET MVC中使用 Bootstrap table插件的更多相关文章

  1. bootstrap table 插件多语言切换

    在bootstrap中的bootstrap table 插件在多语言切换的审核,只需要如下操作 引入bootstrap-table-locale-all.js文件 $('#Grid').bootstr ...

  2. ASP.NET Identity系列02,在ASP.NET MVC中增删改查用户

    本篇体验在ASP.NET MVC中使用ASP.NET Identity增删改查用户. 源码在这里:https://github.com/darrenji/UseIdentityCRUDUserInMV ...

  3. 2.ASP.NET MVC 中使用Crystal Report水晶报表

    上一篇,介绍了怎么导出Excel文件,这篇文章介绍在ASP.NET MVC中使用水晶报表. 项目源码下载:https://github.com/caofangsheng93/CrystalReport ...

  4. 如何在 ASP.NET MVC 中集成 AngularJS(2)

    在如何在 ASP.NET MVC 中集成 AngularJS(1)中,我们介绍了 ASP.NET MVC 捆绑和压缩.应用程序版本自动刷新和工程构建等内容. 下面介绍如何在 ASP.NET MVC 中 ...

  5. 《Entity Framework 6 Recipes》中文翻译系列 (20) -----第四章 ASP.NET MVC中使用实体框架之在MVC中构建一个CRUD示例

    翻译的初衷以及为什么选择<Entity Framework 6 Recipes>来学习,请看本系列开篇 第四章  ASP.NET MVC中使用实体框架 ASP.NET是一个免费的Web框架 ...

  6. 在 ASP.NET MVC 中充分利用 WebGrid (microsoft 官方示例)

    在 ASP.NET MVC 中充分利用 WebGrid https://msdn.microsoft.com/zh-cn/magazine/hh288075.aspx Stuart Leeks 下载代 ...

  7. 如何在 ASP.NET MVC 中集成 AngularJS(1)

    介绍 当涉及到计算机软件的开发时,我想运用所有的最新技术.例如,前端使用最新的 JavaScript 技术,服务器端使用最新的基于 REST 的 Web API 服务.另外,还有最新的数据库技术.最新 ...

  8. 在ASP.NET MVC中实现基于URL的权限控制

    本示例演示了在ASP.NET MVC中进行基于URL的权限控制,由于是基于URL进行控制的,所以只能精确到页.这种权限控制的优点是可以在已有的项目上改动极少的代码来增加权限控制功能,和项目本身的耦合度 ...

  9. NPOI以及在ASP.NET MVC中的使用

    NPOI以及在ASP.NET MVC中的使用 1.前言 相信大家在工作中经常要遇到一些导入导出Execl操作.学习贵在分享,分享使人快乐,园子里的前辈已经有很多好的文章,鄙人也是能力有限,在这里把这些 ...

随机推荐

  1. JS动态生成<style>

    var nod = document.createElement(“style”), str = “body{background:#000;color:#fff} a{color:#fff;text ...

  2. A. Round House

    A. Round House time limit per test 1 second memory limit per test 256 megabytes input standard input ...

  3. c#动态生成word,在本地可以执行,但发布到iis上出错解决方案

    报错点: Microsoft.Office.Interop.Word.DocumentClass.SaveAs 解决方案: 1.在"开始"->"运行"中输 ...

  4. Selenuim+Python之元素定位总结及实例说明

    网页自动化最基本的要求就是要定位到各个元素,然后才能对该元素进行各种操作(输入,点击,清除,提交等),所以笔者今天来总结下Selenuim+Python最基本的几种定位方式及实例说明,希望能帮助到大家 ...

  5. IBATIS事务处理 - - 博客频道 - CSDN.NET

    body { font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI ...

  6. openstack controller ha测试环境搭建记录(一)——操作系统准备

    为了初步了解openstack controller ha的工作原理,搭建测试环境进行学习. 在学习该方面知识时,当前采用的操作系统版本是centos 7.1 x64.首先在ESXi中建立2台用于测试 ...

  7. Unity NGUI UIPanel下对粒子的剪裁

    使用 unity 做游戏开发时,有时需要在scroll view下使用粒子,但粒子是不会被 UIPanel 所裁剪的,本人提供了脚本 ParticleSystemClipper,用来处理这种情况.思路 ...

  8. ios开发环境配置及cordova安装与常用命令

    一.ios开发环境配置 1.首先要有台Mac Book,如果有Mac Book,跳过步骤2.3.4,如果没有,执行步骤2.3.4: 2.下载并安装VMware Workstation,最好是下最新版本 ...

  9. (简单) POJ 2387 Til the Cows Come Home,Dijkstra。

    Description Bessie is out in the field and wants to get back to the barn to get as much sleep as pos ...

  10. ubuntu 14.04 安装torch及编译环境zbstudio

    ubuntu 14.04 安装torch及编译环境zbstudio torch zbstudio 本来是安装官网给的步骤安装torch的,可是碰到一系列的问题,后来参考网上的安装方法安装成功了 官网安 ...