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 473427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T00:11:08+00:00 2026-05-13T00:11:08+00:00

I have a view which contains a users id and an image column. Here’s

  • 0

I have a view which contains a users id and an image column.

Here’s what i’ve tried doing to retrieve the image but i keep getting a box with an red x instead of the actual image.

View

<td><img src="<%= Url.Action( "DisplayImage" , "User" , new { id = item.id} ) %>" alt="" /></td>

Controller

  public FileContentResult DisplayImage(string id)
    {
        byte[] image = repository.GetImage(id);
        return File(image, "image/jpg");
    }

i’ve also tried returning an ActionResult instead and that didn’t work either.

Repository

    public Byte[] GetImage(string id)
    {

        var image = db.GetImage(id).First<GetImageResult>();

        if (image == null)
            return null;
        return image.UserImage;
    }

LinqTOSQL Class

    [Function(Name="dbo.GetImage")]
public ISingleResult<GetImageResult> GetImage([Parameter(DbType="VarChar(8)")] string id)
{
    IExecuteResult result = this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), id);
    return ((ISingleResult<GetImageResult>)(result.ReturnValue));
}

public partial class GetImageResult
{
    private System.Byte[] _userImage;

    public GetImageResult()
    {
    }


    [Column(Storage="_userImage", DbType="Image")]
    public System.Byte[] UserImage
    {
        get
        {
            return this._userImage;
        }
        set
        {
            if ((this. _userImage!= value))
            {
                this. _userImage = value;
            }
        }
    }
}

I’ve been killing myself all day trying to get this to work, but it just isn’t working.
The return type on the stored procedure is an integer (atleast when i look at parameters in
SQL Server Management Studio it says integer), but i can’t redefine that now can i?

It’s actually hitting the DisplayImage Action with the correct parameters within the UserController and returning File(imageByteArray, “image/jpg”) but only a box with red x is being displayed.
Any help would be greatly appreciated.

edit: I’ve tried debugging by adding a Reponse.BinaryWrite(imageByteArray) within the action result and hitting the url directly by goign to http://localhost/User/DisplayImage?id=10101010 and the image for that user is displayed in mspaint.

edit2: I also did a view source and my html for that image tag came out as following.

<td>
    <img src='/User.mvc/GetImage?id=U00915441' alt="" />
</td>

Thanks

  • 1 1 Answer
  • 0 Views
  • 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-13T00:11:09+00:00Added an answer on May 13, 2026 at 12:11 am

    Look at this question I had from a while back – the solution was special ActionResult type for images

    Edit: Here’s my code. I’m actually creating an ImageResult class from an Image that I created with GDI+ like this :

     return new ImageResult()
     {
          ImageFormat = spriteInfo.ImageFormat,
          EncodedImageBytes = spriteInfo.GetImageStream()
     };
    

    The image result class is. You’ll notice if I provide an EncodedImageBytes parameter it will send that to the output stream. This looks like exactly what you want. On the other hand if you’re just passing in an Image then it will just write that Image out to the output stream.

     public class ImageResult : ActionResult
        {
            public ImageResult() { }
            public int? Quality { get; set; }
            public Image Image { get; set; }
            public ImageFormat ImageFormat { get; set; }
            public byte[] EncodedImageBytes { get; set; }
    
            public override void ExecuteResult(ControllerContext context)
            {
                // verify properties 
                if (EncodedImageBytes == null)
                {
                    if (Image == null)
                    {
                        throw new ArgumentNullException("Image");
                    }
                }
                if (ImageFormat == null)
                {
                    throw new ArgumentNullException("ImageFormat");
                }
                // output 
                context.HttpContext.Response.Clear();
    
                if (ImageFormat.Equals(ImageFormat.Bmp)) context.HttpContext.Response.ContentType = "image/bmp";
                if (ImageFormat.Equals(ImageFormat.Gif)) context.HttpContext.Response.ContentType = "image/gif";
                if (ImageFormat.Equals(ImageFormat.Icon)) context.HttpContext.Response.ContentType = "image/vnd.microsoft.icon";
                if (ImageFormat.Equals(ImageFormat.Jpeg)) context.HttpContext.Response.ContentType = "image/jpeg";
                if (ImageFormat.Equals(ImageFormat.Png)) context.HttpContext.Response.ContentType = "image/png";
                if (ImageFormat.Equals(ImageFormat.Tiff)) context.HttpContext.Response.ContentType = "image/tiff";
                if (ImageFormat.Equals(ImageFormat.Wmf)) context.HttpContext.Response.ContentType = "image/wmf";
    
                // output stream
                Stream outputStream = context.HttpContext.Response.OutputStream;
                if (EncodedImageBytes != null)
                {
                    outputStream.Write(EncodedImageBytes, 0, EncodedImageBytes.Length);
                }
                else
                {
                    ImageUtil.SaveImageToStream(outputStream, Image, ImageFormat, Quality);
                }
            }
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.