c# - 如何从数据表中的服务器端jquery数据表获取图像src值?

标签 c# jquery datatables

我正在使用jquery数据表并使用ajax调用填充该数据表并且它工作正常,但现在我需要在列中显示图像,但我不知道如何绑定(bind)这些图像。图像链接来自category_image中的后端.

后端:

var displayedCategories = filteredCategories;
var result = from c in displayedCategories select new[] 
{c.id, c.category_name, c.category_image,c.id};
return Json(new{
sEcho = param.sEcho,
iTotalRecords = lstAllCategories.Count,
iTotalDisplayRecords = 10,
aaData = result},JsonRequestBehavior.AllowGet);

前端:

$('#tblInterests').dataTable({
"bServerSide": true,
"sAjaxDataProp": "aaData",
"bProcessing": true,
"bLengthChange": false,
"sPaginationType": "full_numbers",
"bSort": true,
"aoColumns":[
{"sName": "id"},
{"sName": "category_name" },
{"sName": "category_image",
"bSearchable": false,
"bSortable": false,
"mRender": function (data) {
return '<img src="" width="50" height="50" />'
}
},
{"mData": "Id",
"bSearchable": false,
"bSortable": false,
"sWidth": "40px",
"mRender": function (data) {
return '<button class="btn btn-primary" type="button" >Edit</button>'
}
},
],
"ajax": "/Admin/InterestsJson",
"columns": [
{ "data": "id" },
{ "data": "category_name" },
{ "data": "category_image" },
{ "data": "id" }
]
});

最佳答案

mRender中,data (==category_image) 应设置为图像的src:

...
{ "sName": "category_image",
  "bSearchable": false,
  "bSortable": false,
  "mRender": function(data, type, full) {
     return '<img src="'+data+'" width="50" height="50" />'
  }
}
...

关于c# - 如何从数据表中的服务器端jquery数据表获取图像src值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31353862/

相关文章:

c# - 在 WCF 中使用 MvcMailer

c# - 复杂 - 在 Powershell c# 中用 Regex 替换

javascript - 数据表刷新按钮和旋转很棒的图标

javascript - 在 JQuery 函数中选择一个元素

php - jQuery $.post() 和 MySQL 问题

Jquery Datatable 没有响应

C# 如何使用 .OrderBy 处理多列并将列号解码为列名?

c# - 在 windows phone 中使用 FFMPEG 将 .TS 文件转换为 .mp3

c# - 如何定义包含整数作为值的 C# 枚举?

javascript - 如何使用 haml 将内插的 ruby​​ 对象正确格式化为 Rails 中的 jquery 选择器?