【发布时间】:2011-01-27 08:12:01
【问题描述】:
我试图在 jqGrid 中显示来自记录的图像,但它不起作用。
我的 jqGrid 中的每条记录都有一个 id。为了从我的数据库表中获取图像,我编写了一个 ActionResult,它将存储在数据库表中的文件(图像)返回到 id。
因为每条记录都有一个唯一的 id,所以我在我的页面中有一个隐藏字段,jq 应该存储格式化到格式化程序的实际记录的实际 id。
当我用firebug查看代码时,似乎隐藏字段的方式不起作用。
也许你有一个想法?
这是我的代码:
<input type="hidden" name="cellvalue" value="" />
<script type="text/javascript">
$(function () {
$("#PartialIndexGrid").jqGrid({
url: '/@ViewContext.RouteData.Values["Controller"].ToString()/IndexGridData',
datatype: 'json',
mtype: 'POST',
colNames: ['Details', 'Bearbeiten','Bild', 'Titel', 'Bearbeitungsort', 'Status'],
colModel: [
{ name: 'Details', index: "Details", edittype: 'select', align: "center", width: 45, formatter: 'showlink', formatoptions: { baseLinkUrl: '/Shared/Details/', addParam: ''} },
{ name: 'Bearbeiten', index: "Bearbeiten", edittype: 'select', align: "center", width: 80, formatter: 'showlink', formatoptions: { baseLinkUrl: '/Shared/Edit/', addParam: ''} },
{ name: 'Bild', index: 'Bild', edittype: 'image', formatter: imageFormatter },
{ name: 'Titel', index: 'Titel'},
{ name: 'Bearbeitungsort', index: 'Bearbeitungsort' },
{ name: 'AuftragStatus', index: 'AuftragStatus'}
],
pager: $("#PartialIndexGridpager"),
rowNum: 10,
rowList: [5, 10, 20, 30],
sortname: 'Titel',
sortorder: "asc",
viewrecords: true,
width: 942,
caption: ''
})
});
function imageFormatter(cellvalue, options, rowObject) {
$("cellvalue").val(cellvalue);
return '<img src="@Url.Action("AuftragDBImage", "Shared", new { id = Request.Form["cellvalue"]})" />';
};
public ActionResult AuftragDBImage(Guid id)
{
try
{
var auftrag = _db.Auftrag.Where(x => x.Auftrag_GUID == id).Select(x => x).Single();
return File(auftrag.Bild, "image/jpeg");
}
catch (Exception)
{
return File(pfaddummybild, "image/jpeg");
}
}
问候, 浮动
【问题讨论】:
-
我在jqGrid中没有找到任何隐藏字段,但是您写道“似乎隐藏字段的方式不起作用”。此外,自定义格式化程序
imageFormatter看起来很奇怪。为了让其他人能够验证您的代码,您应该说明Build的哪些值具有来自服务器的 JSON 响应以及自定义格式化程序应该产生什么结果。
标签: c# asp.net jquery asp.net-mvc jqgrid