Click here to Skip to main content
14,927,434 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
My requirement is to get the images from the database and display in front end.In my case i am using asp.net MVC . Database ir oracle and the data type of the image is blob .The follwing is my code

**Model**

This is the Model for the class and it has two properties ImageDisplay and ImageStream.

C#
          public class SelectionModel
   {

      public byte[] ImageDsiplay
{
    get;
    set;
}


         public MemoryStream ImageStream
{
    get;
    set;
}


      }
                **Controller Code**

   In the controller i am trying the get the image from he database and assign to the Model.

                public ActionResult Index()
{
   SelectionModel sel = new SelectionModel();

   List<SelectionModel> lissel = new List<SelectionModel>();
    byte[] imagedata;

    string sql = "select filecontent from filestore";

    OracleConnection con = new OracleConnection(ConStr);
    OracleCommand com = new OracleCommand(sql, con);

    try
    {
        con.Open();

        OracleDataReader dr;

        dr = com.ExecuteReader();

        while (dr.Read())
        {
            //  SelectionModel sel = new SelectionModel();

            imagedata = (byte[])dr[0];

            sel.ImageDsiplay = imagedata;

            var stream = new MemoryStream(sel.ImageDsiplay);

            sel.ImageStream = stream;

            lissel.Add(sel);



            //  ViewData["image"] = sel.ImageStream;

            // return File(sel.ImageStream, "image/png");

        }
     //   return File(sel.ImageStream, "image/png");


    }



    catch (Exception ex)
    {
    }

Here i am trying to return the list .
C#
    return View(lissel);
}

      **View Code**

The Following is the view code and it should display the image .

C#
@model IEnumerable<goldforgold.models.selectionmodel>





HTML
   <table>

   <tr>

   <td>


  @foreach (var item in Model)
  {
   <img  src="@Url.Action("Index", "Selection")" alt="myimage" />

     // <img src="@(item.ImageStream).png" alt="Alternate Text" />
  }

  </td>
  </tr>

</table>

My requirement is to get the images from the database and display in front end.In my case i am using asp.net MVC . Database ir oracle and the data type of the image is blob .The follwing is my code
**ISSUE**


The issue is i am not able to display the images from the database.
Posted
Updated 8-Jul-20 23:10pm
v2

1 solution

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900