Note that there are some explanatory texts on larger screens.

plurals
  1. PORendering image Byte data already in the view
    primarykey
    data
    text
    <p>I'm new to MVC (coming from object oriented C# exe apps) and Stackoverflow. I've been struggling with trying to run code efficiently using MVC. I have Model data that returns from the database and along with that data is a field of bytes that are a jpeg image. At this stage I've made one call to the database...</p> <p>Now what I'm stuck on is that once the populated model data is in the view to be rendered, I can't simply loop over it and render the image in each data row. The only thing that I've found to make it work is to call and Action method that returns a FileContentResult, but this requires a new call back to the database for each image anew.</p> <p>For solutions I've tried three different approaches that have netted the following problems:</p> <ol> <li>I can't seem to pass the byte array back to the controller via an Action method to satisfy how MVC wants to receive the FileContentResult back in the view. The Action method only wants to accept simple types. </li> <li>I obviously don't want to ask the controller to go back to the database for the byte data that I already have in the View, especially when this will involve several round trips for each entry in my Model data.</li> <li>Using Data Uri works, but it's not supported by enough browsers yet.</li> </ol> <p>Could someone tell me what the best way to handle issues like this? Do I need to work with problem 1, or 2, or is there a different approach that I'm missing?</p> <p>Here is the code I tried to use originally in problem 1 to pass the byte array back to the controller so I can render the FileContentResult: </p> <pre><code>&lt;img src=" @{Html.RenderAction("RenderMemberImage", "Home", new { @pic = x.ThumbnailData });}" /&gt; [HttpGet] public FileContentResult RenderMemberImage(byte[] pic) { return new FileContentResult(pic, "mime/jpeg"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload