title: ASP.Net MVC - Img Src Server Path
body: <p>Visual Studio 2012 - ASP.net - MVC 4</p>
  
  <p>I am having troubles displaying an image from a server path which is stored in a database.</p>
  
  <p>I am using HttpPostedFileBase to retrieve the file the user has uploaded:</p>
  
  <pre><code>using (var uow = _db.CreateUnitOfWork())
              {
                  if (imageUpload != null &amp;&amp; imageUpload.ContentLength &gt; 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;
              }
  </code></pre>
  
  <p>This will save the absolute path of the uploaded file into the database and save the file onto the server. When I try to retrieve this path to display an image file in a view all I get is a blank square like the file is not being found (about:blank when right click -> copy image url). I know the path is correct because I am using it in a different view to allow users to download files, which is working correctly. Also I am allowing the user to edit the file which successfully deletes the old and uploads a new one. The only problem I am having is displaying an image in a view.</p>
  
  <p>I have tried:</p>
  
  <pre><code>&lt;img src="@Html.Encode(Model.ImageLoc)" /&gt;
  &lt;img src=@Url.Content(Model.ImageLoc)" /&gt;
  </code></pre>
  
  <p>Would anyone be able to suggest anything?</p>