数据库的数据绑定后如何在页面显示

作者:老岑
如何去绑定数据库的表,首先你要先有个表,所以就要把数据库的表添加进来。
在这里插入图片描述
这是数据库里面的原始表
在这里插入图片描述
我们就先把这个表先绑定起来
public ActionResult Good(LayuiTablePage layuiTablePage)
{
List<PW_Employee> listAcademe = myModels.PW_Employee.OrderBy(m => m.employeeID).Skip(layuiTablePage.GetStartIndex())
.Take(layuiTablePage.limit).ToList();
int intTotalRow = myModels.PW_Employee.Count();
LayuiTableData<PW_Employee> layuiTableData = new LayuiTableData<PW_Employee>()
{
count = intTotalRow,
data = listAcademe
};
return Json(layuiTableData, JsonRequestBehavior.AllowGet);
}
我们通过lambda表达式把表给连接上去。
而表的形态具体要怎么显示,这个就要看你自己的想象力有多么的丰富了。
我自己就没有这么厉害的想象力了,所以我就直接引用了layui的插件,绑定数据。
$(document).ready(function () {
layui.use([‘table’, ‘layer’], function () {
layer = layui.layer,layuiTable = layui.table;
TabTitles = layuiTable.render({
elem: ‘#employee’,
url: “/Main/Good”,
deta:[],
cols: [[
{ type: ‘numbers’, title: ‘序号’ },
{ title: ‘employeeID’, field: ‘employeeID’, hide: true },
{ field: ‘employeeNum’, title: ‘员工编号’, align: ‘center’, width: ‘22%’ },
{ field: ‘employeeName’, title: ‘员工姓名’, align: ‘center’, width: ‘22%’ },
{ field: ‘telphone’, title: ‘联系电话’, align: ‘center’, width: ‘22%’ },
{ field: ‘address’, title: ‘家庭地址’, align: ‘center’, width: ‘22%’ }
]],
page: {
limit: 8,
limits: [ 8, 15, 20, 25, 30, 35, 40, 45, 50],
},
});
});
});
这样就把我们的表给设计出来了。
这是在页面的显示图。
在这里插入图片描述