即時通訊嘗試顯示圖像從jqGrid中的記錄,但它不工作。jqGrid從數據庫中顯示圖像行
我的jqGrid中的每條記錄都有一個id。爲了從我的數據庫表中獲取圖像,我編寫了一個ActionResult,它返回一個存儲在數據庫表中的文件(圖像)到該ID。
因爲每個記錄都有一個唯一的ID,我在我的頁面中有一個隱藏字段,其中jq應該存儲實際記錄的格式化成格式化程序的實際ID。
當我用螢火蟲查看代碼時,似乎隱藏字段的方式不起作用。
也許你有想法嗎?
這裏是我的代碼:
<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` coulmn的哪些值有來自服務器的JSON響應,以及自定義格式化程序應該產生什麼結果。 – Oleg 2011-01-27 09:24:19