ASP.net MVC - Byte-Based Image Series Display []

I want to display a list of images and a description on a webpage using ASP.net MVC. Images are stored in a SQL Server database, and I return them as bytes [].

However, I do not understand how I can display a series of images on a page. I want to do something like this:

<% foreach(Product p in Model.Products)
      Response.Write(p.Description)
      Response.Write(html.Image(p.ImageArray)
%>

But the only code I saw showed one image ...

thanks

Ben

+3
source share
4 answers

Instead of creating a new HttpHandler, you can simply write a controller action that returns the contents of the image file. Then add the images to the page with the src attribute set to the action you created.

EDIT: , [] .

+1

IHttpHandler, :

    public class AlbumArt : IHttpHandler
        {
            public void ProcessRequest(HttpContext Context)
            {
byte [] b = your image...;
    Context.Response.ContentType = "image/jpeg";
                        Context.Response.BinaryWrite(b);
    }
    }

, html, -

<img src="AlbumArt.ashx?imageId=1" />
+1

HTML - , HTML. . . , . HttpHandler .

+1

( IMG ), . , , .

0
source

Source: https://habr.com/ru/post/1702607/


All Articles