Layui表格中显示图片
发布时间
阅读量:
阅读量
开发工具与关键技术:VS、MVC
作者:何德润
撰写时间:2019.8.15
首先自定义一个函数用于获取对应的ID字段值接着通过该ID字段值访问控制器页面获取对应的图片资源最后将获取到的图片资源传递给LayUI的数据表格进行展示
driver.render({
elem: "#driver",
url: "Selectdriverxinxi",
cols: [[
{ type: 'radio' },
{ field: 'pilotName', title: '姓名', align: 'center' },
{ field: 'pilotPhone', title: '联系电话', align: 'center' },
{ field: 'DriverIDNumber', title: '身份证号', align: 'center' },
{ field: 'drivernumber', title: '从业资格证号', align: 'center' },
{
field: 'piloPhoto', title: '像片', align: 'center', templet: function dataURLtoFile(d) {
var img = "<img src='selectPaymentLog?DriverID=" + d.DriverID + "' alt='Alternate Text' style='width:100px;height:80px;'/>"; return img;
}
}
]],
page: {
limit: 5,
limits: [5, 10, 15, 20, 25],
}
})
控制器页面图片查询代码:
public ActionResult selectPaymentLog(int DriverID)
{
try
{
var PaymentLogimg = (from tbPayment in myModels.S_Driver
where tbPayment.DriverID == DriverID
select new
{
tbPayment.piloPhoto
}).Single();
byte[] stuImg = PaymentLogimg.piloPhoto;
return File(stuImg, @"image/jpg");
}
catch (Exception e)
{
Console.WriteLine(e);
return Json("failed", JsonRequestBehavior.AllowGet);
}
}
效果如图:

全部评论 (0)
还没有任何评论哟~
