加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

MVC bootstrap-table显示数据时显示No matching records found

发布时间:2020-12-17 20:46:34 所属栏目:安全 来源:网络整理
导读:问题:bootstrap-table加载数据不显示 @{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml"; } script $(function () { InitMainTable(); document.onkeydown = function (e) { var ev = document.all ? window.event : e; if (ev.keyCod

问题:bootstrap-table加载数据不显示

@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<script>
  $(function () {
  InitMainTable();
  document.onkeydown = function (e) {

  var ev = document.all ? window.event : e;
  if (ev.keyCode == 13) {// 如(ev.ctrlKey && ev.keyCode==13)为ctrl+Center 触发
  $("#table").bootstrapTable(‘refresh‘);
  }
}
  $("#rearch").click(function () {
  $("#table").bootstrapTable(‘refresh‘);
  });
});
 function InitMainTable() {
  //先销毁表格
  $("#table").bootstrapTable(‘destroy‘);
  $("#table").bootstrapTable({
  method: "get"
  ,url: "/Type/DataList"
  ,striped: true,//表格显示条纹
  pagination: true,// 是否显示分页
  pageSize: 10,//每页显示条数
  pageNumber: 1,//当前第几页
  search: true,//显示搜索框
  buttonsAlign: "right",//按钮对齐方式
  pageList: [5,10,15,20,25],
  showColumns: true,
  showRefresh: true,//是否显示刷新按钮
  sidePagination: "server",//表示从服务端获取数据
  queryParamsType: "undefined",//定义参数类型
  queryParams: function (params) {
  //console.log(params);
  var param = {
  keyword: $("#search").val(),//搜索
  pageIndex: params.pageNumber,
  pageSize: params.pageSize
  };
    return param;
  },
  columns: [{
  field: "TypeName"
  ,title: "名称"
  ,sortable: true
  },{
  field: "Typevalue"
  ,title: "类型值"
  ,{
  field: "FullPath"
  ,title: "表名"
  ,{
  field: "StateName"
  ,title: "是否显示"
  ,sortable: true
  ,formatter: function (value,row,index) {
  var isdisplay = row["StateName"];
  if (isdisplay == "6f9619ff-8b86-d011-b42d-34c04fc964ff") {
  isdisplay = ‘ <span class="label label-lg label-yellow arrowed-in">是</span>‘;
  } else {
  isdisplay = ‘<span class="label label-lg label-purple arrowed">否</span>‘;
  }
  return isdisplay;
  }
  },{
  title: ‘操作‘,
  align: ‘center‘,
  width: 230,
  formatter: function (value,index) {

  var icon = ‘<button class="btn btn-xs btn-primary" onclick="Update(‘‘ + row.TyId + ‘‘)"><i class="icon-edit bigger-120">编辑</i></button> ‘

  icon += ‘<button class="btn btn-xs btn-danger" onclick="Del(‘‘ + row.TyId + ‘‘)"><i class="icon-trash bigger-120">删除</i></button>‘;

  return icon;
  }
}],
onLoadSuccess: function (data) {
  console.log(data);
},
onLoadError: function () {
  alert("数据加载失败!");
}
});
}
//删除
function Del(tyid) {
  if (confirm("你确定要删除吗?")) {
   $.post("/Type/Reovme",{ tyid: tyid },function (data) {
    if (data.code == 200) {
      window.location.reload();
    } else {
      layer.msg(data.msg,{ icon: 5 });
    }
  });
  }
}
function Update(typeid) {
  window.location.href = "/Type/AddUpdate?typeId="+typeid;
}
function Add() {
  window.location.href = "/Type/AddUpdate";
}
</script>
<div class="input-group col-md-3" style="margin-top:0px">
<input type="text" class="form-control"placeholder="请输入字段名" id="search" / >
<span class="input-group-btn">
<button class="btn btn-sm btn-search" id="rearch">
<i class="icon-search bigger-110"></i>
<span class="bigger-110 no-text-shadow">查找</span>
</button>&nbsp;
<button class="btn btn-sm btn-success" onclick="Add()"><i class="icon-pencil bigger-110">添加</i></button>
</span>
</div>
<table class="table table-hover table-striped" border="0" id="table" style="border-width: 0px; border-collapse: collapse;">
</table>

代码是没有问题的但是就是一直不显示,加载的时候是有数据输出,当时找了好久。一直都找不出来,后来发现控制器返回json格式有问题。

//控制器

/// <summary>
/// 查询角色表
/// </summary>
/// <returns></returns>
public ActionResult getRoleAll(int pageIndex,int pageSize)
{
  ISys_RoleBLL irb = new Sys_RoleBLL();
  List<Sys_Role> list = irb.getRoleAll();
  var data = (from role in list
select new
{
  role.RoId,
  role.EnCode,
  role.FullName,
  DeleteMark=Convert.ToInt32(role.DeleteMark).ToString()=="1"?"可用":"不可用",
  }).Skip((pageIndex-1)*pageSize).Take(pageSize);
    var resut = new { rows = data }; 当时没有加上这句话,直接返回data数据,导致页面有数据输出,table表格无数据。这里需要返回匿名类型的数据   return Json(resut,JsonRequestBehavior.AllowGet); }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读