简体   繁体   English

如何在ASP.NET MVC中使用jQuery将varbinary图像显示到html表?

[英]How to display varbinary image to html table using jQuery in ASP.NET MVC?

I am trying to display a varbinary image from a SQL table to html table data using jQuery and web service. 我正在尝试使用jQuery和Web服务从SQL表到HTML表数据显示varbinary图像。 Please help me how to convert int and how to display it. 请帮助我如何转换int以及如何显示它。

My code is like this: 我的代码是这样的:

Web service: 网络服务:

[WebMethod]
public a[] Bindpics()
{
    DataTable dt = ga.retrievedata("select Picture from T_Sam");

    List<a> details = new List<a>();

    foreach (DataRow dtrow in dt.Rows)
    {
        a m = new a();
        m.Pic = (byte[])dtrow["Picture"];
        details.Add(m);
    }

    return details.ToArray();
}

public class a
{
   public byte[] Pic { get; set; }
}

jQuery: jQuery的:

success: function (data) {
        for (var i = 0; i < data.d.length; i++) {
            $("#tbDetails").append("<tr><td>"
                + "<img src=" + "'" + data.d[i].Pic + "'" + " />" + "</td></tr>");
        }

I am getting an error 我收到一个错误

Unable to cast object of type \'System.DBNull\' to type \'System.Byte[]\' 无法将类型\\ u0027System.DBNull \\ u0027的对象强制转换为类型\\ u0027System.Byte [] \\ u0027

It is not displaying the image. 它没有显示图像。

Please help me to convert it. 请帮我转换。

我从Web服务转换了图像,然后问题解决了...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 asp.net mvc 如何在html表中显示组数据 - How to display group data in html table asp.net mvc 如何使用ASP.NET MVC3在表中显示Azure Blob存储的所有图像? - How to display all the image from Azure Blob Storage in table using ASP.NET MVC3? 转换Varbinary上传图像MVC asp.net - Convert Varbinary To upload Image MVC asp.net ASP.Net jQuery网络摄像头图像到数据库varbinary(max) - ASP.Net jQuery webcam image to database varbinary(max) 如何将 VarBinary 文档检索到 ASP.NET MVC 视图 - How to retrieve a VarBinary document to an ASP.NET MVC view How to insert HTML table data into SQL Server in a single batch by using jquery ajax and structured parameter with ASP.NET MVC controller - How to insert HTML table data into SQL Server in a single batch by using jquery ajax and structured parameter with ASP.NET MVC controller 如何在Visual Studio 2012的(数据库)表中手动存储图像并在ASP.NET MVC中使用jquery ajax进行检索 - How to manually store image in (database) table in visual studio 2012 and retrieve using jquery ajax in asp.net mvc ASP.NET MVC Html.Display()使用ViewData? - ASP.NET MVC Html.Display() using ViewData? 如何在asp.net MVC 4中使用子表中的数据显示父表的数据 - How to display the data of the parent table using the data in the child table in asp.net MVC 4 如何创建我在ASP.net MVC中以VARBINARY数据类型存储在数据库中的图像的EDIT方法和EDIT Razor View? - How to create EDIT method and EDIT Razor View for Image which i stored in database in VARBINARY datatype in ASP.net MVC?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM