Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1091129
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:28:36+00:00 2026-05-16T23:28:36+00:00

The question as to how to display an image, stored as an image in

  • 0

The question as to how to display an image, stored as an image in the database and as a byte array in code, has been answered several times (e.g., Display image from database in asp mvc), but what if you want to display the image in the context of a form. That is, I have an object that has several fields, one of which is an image. I have got it working where the user can upload the image and it gets stored as part of the save process, along with the rest of the object fields. But how do I send it back out (and ideally display it) with the rest of the data to populate the Edit form? All of the solutions I’ve seen have some sort of ShowImage action that takes an Id and retrieves the image and streams it to the response. However, I don’t see how this works in this scenario.

The only thing I can think of is to populate the form and then use jquery to retrieve the image and display it in the form, but that’s a lot of extra traffic that seems unnecessary.

Anyone know how to do this?

Thanks.

  • 1 1 Answer
  • 1 View
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:28:37+00:00Added an answer on May 16, 2026 at 11:28 pm

    I would make a controller action that just servers up your image.

    Then in your view that displays the image and other data, just pass it the URL to correct action that will serve up the image with the rest of view data. Then use an img tag to display your image by making the view data URL as the src. The img will call the URL and fetch it for you.

    So to break it down you have two controller actions like GetImage and FormDetails or something and the GetImage is only used to fetch images from your DB and return the byte array as an image response (you could also do some server side checking for security here). The FormDetails action would get all the data including the URL to your image only and put it all together.

    EDIT based on your comment: To get around the two calls you could implement some caching… when it is uploaded you could store it temporarily like:

    // Cache it for 5 mins (and keep it cached until it has not be accessed for 5 mins.
    System.Web.HttpContext.Current.Cache.Insert("YourImage" + imageID.ToString(),
        yourImage, null, System.Web.Caching.Cache.NoAbsoluteExpiration, 
        new TimeSpan(0, 5, 0)); 
    

    Then in your controller action that serves up the image you could check to see if the value exists in the cache first before doing the DB call which will save you the second trip in most cases if your scenario is as described:

    if (System.Web.HttpContext.Current.Cache["YourImage" + imageID.ToString()] == null)
    {
        // get image from DB
    }
    else
    {
        // image is cached so serve it up!
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This compojure question is twofold! How can I display an image object in a
My code below is supposed to display each question ($_POST[questionText]). For each question, it
Please excuse my newbie Question. I'm tryin to display data from a mysql table
This is a followup on the question: ASP.NET next/previous buttons to display single row
Very simple question... I have an array of pixels, how do I display them
Question: In order to store logos in a database and display them dynamically in
I'm trying to display a custom ListView that has a thumbnail image and text
I am trying to display an image stored at local file system outside my
I want to display images stored in my database,however my program is throwing an
string in question: '{images:{0:<div style=\\background:red;width:250px;height:250px;display:block;position:absolute;\\></div>}}' I've tried various combinations of single and double quotes.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.