-1

In this action method I am getting the path of image from the sql database

public ActionResult image(int id)
{
     dbCRMEntities dbx = new dbCRMEntities();
     var img = dbx.CONTACTS.FirstOrDefault(Id => id == Id.CONTACT_ID);
     return View(img);
}

In view,getting the path of image of image

<img src="@Url.Content(Model.IMAGE)" alt="Image" />

but it is only showing the text of alt, how can I render the image.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
Umair
  • 65
  • 7
  • Check this - http://stackoverflow.com/questions/880515/display-image-from-database-in-asp-mvc – Rohit Dec 26 '14 at 11:46
  • You probably have an absolute path of the file in your db. You need a relative path (~/ProfileImages/user115.png) to use the @Url.Content method – John Dec 26 '14 at 11:51
  • Rohit Gupta, this link discussing about image in byte array, my image is stored in local database – Umair Dec 26 '14 at 11:55
  • show your `Model` please, spicificaly - `Model.IMAGE` `Type`. – teo van kot Dec 26 '14 at 12:43

1 Answers1

2

This works for me

In your Controller

public ActionResult image(int id)
{
     dbCRMEntities dbx = new dbCRMEntities();
     String img = dbx.CONTACTS.FirstOrDefault(Id => id == Id.CONTACT_ID);
     return base.File(img, "image/jpg");
}

In your View

<img src="@Url.Action("image","ControllerName")" />

Make sure that your path is correct

Sheraz
  • 567
  • 4
  • 22