当前位置: 移动技术网 > IT编程>开发语言>.net > MVC bootstrap-table显示数据时显示No matching records found

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

2018年12月18日  | 移动技术网IT编程  | 我要评论

一肖中平特,超幸福三部曲,宜修传

问题: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: "类型值"
  , sortable: true
  }, {
  field: "fullpath"
  , title: "表名"
  , sortable: true
  }, {
  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, row, 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);
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网