0

In my MVC view i'm able to get Image ItemID now want to render it i'm doing this as:

   // 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"/>

please someone can hep to what mistake i'm doing here

Amit Sharma
  • 1,088
  • 1
  • 19
  • 44
  • Why not just render the image URL into the `src` field using `Sitecore.Resources.Media.MediaManager.GetMediaUrl(myImageItem)`? – jammykam Dec 24 '14 at 16:41
  • I agree with Jammykam. That to me seems like the easiest way to render the image unless you need it page editor enabled. – Varun Nehra Dec 25 '14 at 09:01

1 Answers1

0

You need a dedicated action that will return the contents of the actual image by it's id:

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

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

After that you can use this action in your view:

<img src="@Url.Action("Image", "SomeController", new {imageID = myImageItem})"/>
Vsevolod Goloviznin
  • 12,074
  • 1
  • 49
  • 50