在我尝试过的内容下面,但该图像未显示在替代文本上。它未显示存储在数据库中的字节类型的图像
using System;
using System.Xml.Serialization;
using System.Collections.Generic;
namespace tf.PriceService.Core.Models.Betway
{
[XmlRoot(ElementName = "Keyword")]
public class Keyword
{
[XmlAttribute(AttributeName = "type_cname")]
public string Type_cname { get; set; }
[XmlAttribute(AttributeName = "cname")]
public string Cname { get; set; }
[XmlText]
public string Text { get; set; }
}
[XmlRoot(ElementName = "Keywords")]
public class Keywords
{
[XmlElement(ElementName = "Keyword")]
public List<Keyword> Keyword { get; set; }
}
[XmlRoot(ElementName = "Outcome")]
public class Outcome
{
[XmlElement(ElementName = "Name")]
public string Name { get; set; }
[XmlElement(ElementName = "Quicklink")]
public string Quicklink { get; set; }
[XmlAttribute(AttributeName = "id")]
public string Id { get; set; }
[XmlAttribute(AttributeName = "index")]
public string Index { get; set; }
[XmlAttribute(AttributeName = "type_cname")]
public string Type_cname { get; set; }
[XmlAttribute(AttributeName = "cname")]
public string Cname { get; set; }
[XmlAttribute(AttributeName = "starting_price")]
public string Starting_price { get; set; }
[XmlAttribute(AttributeName = "price_num")]
public string Price_num { get; set; }
[XmlAttribute(AttributeName = "price_den")]
public string Price_den { get; set; }
[XmlAttribute(AttributeName = "price_dec")]
public string Price_dec { get; set; }
}
[XmlRoot(ElementName = "Market")]
public class Market
{
[XmlElement(ElementName = "Name")]
public string Name { get; set; }
[XmlElement(ElementName = "Outcome")]
public List<Outcome> Outcome { get; set; }
[XmlAttribute(AttributeName = "id")]
public string Id { get; set; }
[XmlAttribute(AttributeName = "index")]
public string Index { get; set; }
[XmlAttribute(AttributeName = "type_cname")]
public string Type_cname { get; set; }
[XmlAttribute(AttributeName = "cname")]
public string Cname { get; set; }
[XmlAttribute(AttributeName = "handicap")]
public string Handicap { get; set; }
[XmlAttribute(AttributeName = "situation_index")]
public string Situation_index { get; set; }
[XmlAttribute(AttributeName = "each_way_active")]
public string Each_way_active { get; set; }
[XmlAttribute(AttributeName = "each_way_fraction_den")]
public string Each_way_fraction_den { get; set; }
[XmlAttribute(AttributeName = "each_way_position")]
public string Each_way_position { get; set; }
[XmlAttribute(AttributeName = "tricast")]
public string Tricast { get; set; }
[XmlAttribute(AttributeName = "forecast")]
public string Forecast { get; set; }
[XmlAttribute(AttributeName = "interval_from")]
public string Interval_from { get; set; }
[XmlAttribute(AttributeName = "interval_to")]
public string Interval_to { get; set; }
}
[XmlRoot(ElementName = "Event")]
public class Event
{
[XmlElement(ElementName = "Name")]
public string Name { get; set; }
[XmlElement(ElementName = "Quicklink")]
public string Quicklink { get; set; }
[XmlElement(ElementName = "Keywords")]
public Keywords Keywords { get; set; }
[XmlElement(ElementName = "Market")]
public List<Market> Market { get; set; }
[XmlAttribute(AttributeName = "id")]
public string Id { get; set; }
[XmlAttribute(AttributeName = "cname")]
public string Cname { get; set; }
[XmlAttribute(AttributeName = "start_at")]
public string Start_at { get; set; }
[XmlAttribute(AttributeName = "home_team_cname")]
public string Home_team_cname { get; set; }
[XmlAttribute(AttributeName = "away_team_cname")]
public string Away_team_cname { get; set; }
[XmlAttribute(AttributeName = "started")]
public string Started { get; set; }
}
[XmlRoot(ElementName = "EventList")]
public class EventList
{
[XmlElement(ElementName = "Event")]
public List<Event> Event { get; set; }
}
}
**查看代码**
public ActionResult viewimage()
{
List<image> tlist = new List<image>();
using (SqlConnection con = new SqlConnection(connectionString))
{
using (SqlCommand cmd = new SqlCommand("getImage", con))
{
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
var imga = new image();
{
imga.images = (byte[])reader["img"];
ViewBag.Base64String = "data:image/png;base64," + Convert.ToBase64String(imga.images, 0, imga.images.Length);
}
tlist.Add(imga);
}
}
}
ViewBag.s = tlist;
return View();
}