Return Image (Blob from Database)

Asked

Viewed 175 times

0

I am unable to return the images of a controller. Below I explain all the encoding:

I created a controller, and a view for this controller that returns the image that is in an Oracle blob field. It worked, usually with the controller and view below:

 public class ImagemController : Controller
    {
        // GET: Imagem
        public ActionResult Index()
        {
            return View();
        }
        public ActionResult GetImagem(int id)
        {
            Entities1 tabela = new Entities1();

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

View:

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Teste de Imagem</h2>

<img src="@Url.Action("GetImagem")" width="100"/>

Now, I created a new controller, to search for stock information and in this controller I have the IDBLOB attribute, as below:

 public class ProntaEntregaController : Controller
    {
        // GET: ProntaEntrega

      public ActionResult Index()
        {
            Entities1 Estoque = new Entities1();

            List<V500_ESTOQUE_PE_WEB> ProntaE = (from p in Estoque.V500_ESTOQUE_PE_WEB select p).Where(x => x.IDBLOB != null).ToList();

            return View(ProntaE);
        }
    }
}

And I made the view, as below just for testing, however, the images are not returned. It’s just an image icon, as if it doesn’t click (I’ll put only a part so it doesn’t get too long):

 <tr>
                <td>
                    @Html.DisplayFor(d => item.COD_REDUZIDO)
                </td>
                <td>
                    @Html.DisplayFor(d => item.TOTAL_KG_PE)
                </td>
                <td>
                    <img src="@Url.Action("GetImage", new { id = item.IDBLOB })" width=100 />
                </td>
            </tr>
  • you remembered to replace the fixed id with your controller parameter, right? In Action GetImagem(int id) ... ... Where(p => p.ID.Equals(843))

  • Yes. I put it on just to test, but still the image doesn’t come

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.