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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T14:44:30+00:00 2026-06-17T14:44:30+00:00

i stored few images in database in binary format, now i want to display

  • 0

i stored few images in database in binary format, now i want to display those images in my view,how can we convert those images from binary format to image format again?

this is my action menthod in my controller

           public ActionResult DislpayAllImage()
           {
            DataSet dsa = new DataSet();
            dsa = objImage.getAllImages();
            DataTable dt = new DataTable();
            dt = dsa.Tables[0];
            if (dt != null)
            {
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                Byte[] image = (Byte[])dt.Rows[i]["UsImage"];
                return File(image, "image/jpg");
             }
            }
        return View();



    }

this is my code in model

     public DataSet getUserImage(int Id)
     {
        DataSet ds = new DataSet();
        try
        {
            DbCommand db = dbcon.GetStoredProcCommand("GetImage");
            dbcon.AddInParameter(db, "@Id", DbType.Int16, Id);
            db.CommandType = CommandType.StoredProcedure;
            return ds = dbconstr.ExecuteDataSet(dbCmd);
        }
        catch(Exception ex)
        {
            return ds = null;
        }
    }

view

 @foreach( var image in ViewData.Images )
 {
  <img src="@Url.Action("DislpayImage", "Home",new { id = image.ImageID })" />
 }

how can i display my image in razor view,also is the above code fine?

  • 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-06-17T14:44:31+00:00Added an answer on June 17, 2026 at 2:44 pm

    You need to call your Controller’s Action(DislpayImage()) from the View like this:

    <img src="<%= Url.Action("DislpayImage", "Controller") %>" alt="myimage" />
    

    or

    <img src="@Url.Action("DislpayImage", "Controller")" alt="myimage" />
    

    Hope it helps you.


    Edit

    Just pass the id of the image you want to display to Controller action

    public ActionResult DislpayImage(int id)
         {
            DataSet dsa = new DataSet();
    
            dsa = objImage.getUserImage(id);
            var imagedata = dsa.Tables[0].Columns["MyImage"];
            return File(imagedata, "image/jpg");
    
         }
    

    Now pass the id of image which you want to display in your view, like this:

    <img src="@Url.Action("DislpayImage", "Controller", new { id="2" })" alt="myimage" />
    

    Now you will get the image with id as 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a few images that I have stored inside the internal storage. I
I was reading from a few tutorials on how to upload my image into
I have a scroll view holding a few images, each one is around 100KB.
I want to implement a database desktop application with Python (PyGTK). Up to now
I want a few Flex (SDK 4.6) applications to share the same stylesheet (stored
I have a database table with images that I need to display. In my
I am using opencv 2.1. In my code I have a few images stored
I have stored a few pictures using Safari's Hold + Save Image option to
I am developing an app for iOS that uses SQLite3 database now i want
I have few images on my server whose names are stored in the phpmysql

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.