0

I created a controller and a view, to fetch data from my database an image, which is in blob format. However, the image is not loaded in the view (I call a method to call this view). I have the controller Image (with the GetImage method), the ReadyDrive controller and the ReadyDelivery view. Within the ReadyDate view, I pass the parameter to get the ID in the GetImage method.

Controller Imagem:

  public ActionResult Index()  
{  
    return View();  
}  
public ActionResult GetImagem(int id)  
{  
    Entities1 tabela = new Entities1();  

    byte[] BlobImg = tabela.DATABINARY.Where(p => p.ID.Equals(id)).Select(p => p.DATA).FirstOrDefault();  
    return File(BlobImg, "image/png");  
}  

Controller ProntaEntrega:

public ActionResult Index(int? reduzido=null)  
  {  
      Entities1 Estoque = new Entities1();  
      List<V500_ESTOQUE_PE_WEB> ProntaE = (from a in Estoque.V500_ESTOQUE_PE_WEB select a).OrderByDescending(x => x.TOTAL_KG_PE).ToList()  
                                         .Where(x => reduzido != null ? x.COD_REDUZIDO.Equals(reduzido) : true).ToList();  


      return View(ProntaE);  
  } 

View ProntaEntrega (a piece of that):

<tbody>  
    @foreach (var item in Model)  
    {  

        <tr>  
            <td class="text-left" width="30%">  
                @Html.DisplayFor(d => item.COD_REDUZIDO)  
            </td>  
            <td class="text-left">  
                @Html.DisplayFor(d => item.DESC_ARTIGO)  
            </td>  
            <td class="text-right">  
                @Html.DisplayFor(d => item.TOTAL_KG_PE)  
            </td>  
            <td>  
                <img src="@Url.Action("GetImage", "Imagem", new { id = @item.IDBLOB})" width=50 />  
            </td>  
        </tr>  

    }  
</tbody> 

Somebody to help me? Tks!

1 Answers1

0

convert the blob in base64. set image src something like below

<img src="data:image/jpeg;base64,iVBORw0KGg" />

reference

Prateek
  • 144
  • 3
  • 14