title: jqGrid show image in row from database
body: <p>im trying to display images from records in jqGrid but it's not working.</p>
  
  <p>Every record in my jqGrid has an id. To get the images out of my database table i wrote a ActionResult that returns a File (image) which is stored in the database table to the id.</p>
  
  <p>Because every record has a unique id i'm having a hidden field in my page where jq should store the actual id of the actual record which is formated to the formatter.</p>
  
  <p>When i look through the code with firebug, it seems that the way with the hidden field is not working.</p>
  
  <p>Maybe you have an idea?</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;input type="hidden" name="cellvalue" value="" /&gt;
  &lt;script type="text/javascript"&gt;
  $(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 '&lt;img src="@Url.Action("AuftragDBImage", "Shared", new { id = Request.Form["cellvalue"]})" /&gt;';
  }; 
  </code></pre>
  
  <p></p>
  
  
  
  
  
  
  
  <pre><code>public ActionResult AuftragDBImage(Guid id)
      {
          try
          {
              var auftrag = _db.Auftrag.Where(x =&gt; x.Auftrag_GUID == id).Select(x =&gt; x).Single();
              return File(auftrag.Bild, "image/jpeg");
          }
          catch (Exception)
          {
  
              return File(pfaddummybild, "image/jpeg");
          }
      }
  </code></pre>
  
  <p>Regards, 
  float</p>