我在 SQL 08 中有 System.Byte[]。我必须将 System.Byte[] 转换为图像并<img>
在 html 的标记中显示该图像。我使用 jquery 从 mvc 获取图像并将其显示在 html 中。
我不使用 View(V) 而不是使用 HTML。
MVC 3 控制器
public ActionResult Get_Leave_IO_Pic(DetailsModel model)
{
TCSServiceReference.MBLServiceSoapClient TCSClient = new TCSServiceReference.MBLServiceSoapClient();
DataSet ds = new DataSet();
DataSet resultds = TCSClient.Get_Employee_Details_Srno(ds, model.EMPSRNO);
Image strJSON = null;
if (resultds.Tables[0] != null && resultds.Tables[0].Rows != null)
{
byte[] byteArrayIn = (byte[])resultds.Tables[0].Rows[0]["EMPPHOT"];
MemoryStream ms = new MemoryStream(byteArrayIn);
Image returnImage = Image.FromStream(ms);
strJSON = returnImage;
}
return Json(new { result = strJSON });
}
HTML
<img src="../images/bis_user.png" width="113" height="104" border="0" alt="" id="ImageStaff" />
jQuery
function GetLeaveIOPic(empsrno) {
$.post("http://Details/Get_Leave_IO_Pic",
{
EMPSRNO: empsrno
},
function (data) {
$.each(data, function (key, value) {
$('#ImageStaff').val(); //How to get image here?
});
}, 'json' );
}