문제

I am sending a bitmap to a View in ASP.NET MVC. I have a property in my ViewModel:

public Bitmap TemplateImage { get; set; }

In my View, I want to be able to render that Bitmap image but I can't figure out how to do it.

도움이 되었습니까?

해결책

One solution would be to create a new action, like this:

public FileContentResult Show(int id)
{
    var category = northwind.AllCategories().Single(c => c.CategoryID == id);
    byte[] imageByte = category.Picture;
    string contentType = "image/jpeg";

    return File(imageByte, contentType);
}

and send an ID for the image instead and reference it like this:

<img src="<%: Url.Action("Show","Image",new { id = Model.Category.CategoryID  }) %>

다른 팁

Since HTTP isn't meant to be able to stuff both HTML and binary image data down the same pipeline in the same connection, this makes passing Bitmap data to your View pointless. You have to find another way around by storing (perhaps temporarily) the Bitmap data and having the client request it via a unique URL.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top