Visual Studio 2012 - ASP.net - MVC 4
I am having problems displaying an image from the path to the server that is stored in the database.
I use HttpPostedFileBase to retrieve the file that the user uploaded:
using (var uow = _db.CreateUnitOfWork()) { if (imageUpload != null && imageUpload.ContentLength > 0) { var fileName = Path.GetRandomFileName() + Path.GetExtension(imageUpload.FileName); var path = Path.Combine(System.Web.Hosting.HostingEnvironment.MapPath("~/Uploads"), fileName); imageUpload.SaveAs(path); achievement.ImageLoc = path; } uow.Add(achievement); Save(uow); return true; }
This will save the absolute path of the downloaded file to the database and save the file on the server. When I try to get this path to display the image file in the view, all I get is an empty square, as this file is not found (near: empty when right-click β copy image URL). I know the path is correct because I use it in a different view so that users can upload files that work correctly. I also allow the user to edit the file, which successfully deletes the old one and loads the new one. The only problem I am facing is to show the image in the view.
I tried:
<img src="@Html.Encode(Model.ImageLoc)" /> <img src=@Url.Content (Model.ImageLoc)" />
Can anyone suggest anything?
source share