我有一个样本,我正在建设,那是使用Northwind数据库。 我有一个视图,其中显示了特定类别的所有产品,并使用ul生成带有图像和产品名称和价格的项目。如何在asp.net mvc中渲染图像?
并且已经到了这样的地步,如果我右键单击我的页面上的图像,我会得到 以下图像url。
这是我提供的操作方法,它只需要分类ID。在我ImageController /图片/显示/ 1
我的操作方法如下:
//
// GET: /Image/Show
public ActionResult Show(int id)
{
var category = northwind.AllCategories().Single(c => c.CategoryID == id);
byte[] imageByte = category.Picture;
string contentType = "image/jpeg";
return this.Image(imageByte, contentType);
}
注:图片是一个byte []
然后我把它在我看来是这样的。 (产品是我认为的型号)
但我仍然无法得到要显示的图像。
导航到操作的URL(/ image/show/1)时图像是否正确显示?如果是这样,那么将图像嵌入到HTML中的方式会有错误。 否则,检查您的方法使用Fiddler2或类似方法返回的数据。 – LorenzCK 2010-08-22 09:57:45