Hello, I'm having trouble displaying dynamic images using Razor syntax in an ASP.NET MVC 5 project.
I have the image path saved in a column in the database, named Image .
Below the code for my view:
@foreach (var item in Model) {
<div class="item branding">
<img src="@Html.DisplayFor(modelItem => item.imagem)" class="img-responsive" alt="" />
<div class="works-overlay">
<div class="wo-inner">
<h4>@Html.DisplayFor(modelItem => item.nome)</h4>
</div>
</div>
</div>
}
But when the view is rendered, the src of the image is correct, the way it is saved in the database: ~ / Content / images / gallery / my-image-123.jpg . But the full image path is incorrect, as shown below:
http://localhost:9474/Albuns/~/Content/images/galeria/minha-imagem-123.jpg
Below is my controller, with a simple listing method.
public ActionResult Index()
{
return View(db.portifolio.ToList());
}
Can anyone help me in how do I display the images correctly? The idea is to store in the database the path of the image on the server, after uploading it. And at the time of rendering, just take the path of the image.
If someone has a better view of storing / displaying images, please feel free to comment.