-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
  • 94,086
  • 102
  • 195
  • 339
Umair
  • 65
  • 6

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
  • 537
  • 4
  • 20