我想从数据库中获取图像并在视图中显示它。从数据库中检索图像但不绑定到图像。这是我的控制器代码
public ActionResult GetSignatureDetails()
{
byte[] image = (from m in objIycEntity.Signatures
where m.SignatureID == 5
select m.Signature1).FirstOrDefault();
var stream = new MemoryStream(image.ToArray());
return new FileContentResult(image, "image/jpeg");
}
这是我的观点
<img src='@Url.Action("GetSignatureDetails","Agent")' />
但是firebug中的图像src总是src =&#34; / Agent / GetSignatureDetails&#34;
任何人都可以帮我解决我的错误
答案 0 :(得分:-1)
public FileContentResult GetSignatureDetails()
{
byte[] image = (from m in objIycEntity.Signatures
where m.SignatureID == 5
select m.Signature1).FirstOrDefault();
return File(image, "image/jpeg");
}
答案 1 :(得分:-1)
我给你一个示例代码希望这会对你有所帮助:
查看:
@model MvcApplication2.Models.AgentProfile
@{
ViewBag.Title = "imageDemo";
}
<h2>imageDemo</h2>
<img width="100" height="80" src="/Profile/ShowImage/2" alt="" />
和控制器代码像这样:
public ActionResult ShowImage(int id)
{
if (id>0)
{
AgentProfile objag = new AgentProfile();
MvcApplication2.Models.Image obj = new MvcApplication2.Models.Image();
obj.ImageID = id;
DataSet ds = obj.SelectImage();
objag.ImageSource = (byte[])ds.Tables[0].Rows[0]["ImageContent"];
//objag.ImageSource = (byte[])row["ImageContent"];
return File(objag.ImageSource, "image/jpg");
}
else
{
return RedirectToAction("Index");
}
}
感谢。