0

在我的 MVC 视图中,我能够获取 Image ItemID 现在想要渲染它,我这样做是:

   // Getting ImageItemID
   ID myImageItemId = new ID(image.Substring(image.IndexOf('{', 0), 38));
   // Getting ImageItem according myImageItemId 
   Item myImageItem = db.GetItem(myImageItemId);
   @Html.Raw(myImageItem)
   <img src="@myImageItem"/>

请有人知道我在这里犯了什么错误

4

1 回答 1

0

您需要一个专门的操作,通过它的 id 返回实际图像的内容:

public ActionResult Image(int imageID)
{
    byte[] image = SomeService.GetImageBytes(imageID);

    return File(image, "image/jpeg");
}

之后,您可以在视图中使用此操作:

<img src="@Url.Action("Image", "SomeController", new {imageID = myImageItem})"/>
于 2014-12-24T15:05:03.383 回答