我'新在ASP.net ...我试图从一个MySQL数据库显示图像,但没有显示... 在我的产品类别我有一个图片的列表:从数据库显示的图像在剃刀/ MVC5(Asp.net)
public partial class product
{
public product()
{
this.orderitems = new List<orderitem>();
this.pictures = new List<picture>();
this.productitemsuppliers = new List<productitemsupplier>();
this.recommendations = new List<recommendation>();
this.reviews = new List<review>();
this.productitems = new List<productitem>();
}
我habve这个方法在我的ProductController的:
static IDatabaseFactory dbFact = new DatabaseFactory();
IUnitOfWork utOfW = new UnitOfWork(dbFact);
public FileContentResult imageGenerate(int id)
{
byte[] image = utOfW.ProductRepository.GetById(id).pictures.ElementAt(0).picture1;
// Another way to get the Byte Array from the Database...
// byte[] image = utOfW.PictureRepository.GetMany(p=>p.product.idProduct==id).ElementAt(0).picture1;
if (image != null) {
return new FileContentResult(image, "image/jpg");
}
return null;
}
在我看来:
@foreach (var item in Model) {
....
<td>
<img id="image" src='@Url.Action("imageGenerate", "ProductController", new { id = item.idProduct})'/>
</td>
}
这似乎是确定,但reseult是不是...
感谢您的帮助