显示来自databasr的图像以在asp.net mvc中查看 [英] display the images from databasr to view in asp.net mvc

查看:75
本文介绍了显示来自databasr的图像以在asp.net mvc中查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是从数据库中获取图像并显示在前端。在我的情况下,我使用的是asp.net MVC。数据库ir oracle和图像的数据类型是blob。以下是我的代码



**型号**



这是该类的Model,它有两个属性ImageDisplay和ImageStream。



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.

          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)
    {
    }



这里我试图返回list。


Here i am trying to return the list .

    return View(lissel);
}

      **View Code**



以下是查看代码,它应该显示图像。




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

@model IEnumerable<goldforgold.models.selectionmodel>
















   <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>



我的要求是从数据库中获取图像并显示在前端。在我的情况下我使用的是asp.net MVC。数据库ir oracle和图像的数据类型是blob。以下是我的代码

**问题**





问题是我无法显示数据库中的图像。


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.

推荐答案

看看这里:

从SQL检索和显示图像MVC视图中的服务器数据库 [ ^ ]

使用ASP.Net C#从DataBase上传和显示图像 [ ^ ]

扩展MVC:从控制器操作中返回图像 [ ^ ]
Have a look here:
Retrieve and display images from SQL Server database in MVC view[^]
Uploading and Displaying Images From DataBase Using ASP.Net C#[^]
Extending MVC: Returning an Image from a Controller Action[^]


这篇关于显示来自databasr的图像以在asp.net mvc中查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆