After i uploaded my image path succesfully to the database i attempted to display it in a grid. In the database i have a filepath like this c:\users\ibn hamza\documents\visual studio 2013\Projects\Blogger\Blogger\Uploads.
I attempted to display the images by doing this
@foreach (var item in Model)
{
<img src="@item.FilePath" height="127" width="127"/>
}
"
when i built the solution i got an empty page without the images but with a placeholder. I inspected the placeholder and i got this path <img src="c:\users\ibn hamza\documents\visual studio 2013\Projects\Blogger\Blogger\Uploads\Lagos-20140103-00347.jpg" height="127" width="127">
I clicked on the path and got no image displayed. Please how do i correctly display the image. I would also provide the controller and the action to store the image
public ActionResult SaveUploadedFile(AddMediaVM model)
{
if (ModelState.IsValid)
{
bool isSavedSuccessfully = true;
foreach (string fileName in Request.Files)
{
var newFile = db.Media.Create();
HttpPostedFileBase file = Request.Files[fileName];
var filetype = Path.GetExtension(file.FileName).ToString();
var filename = file.FileName;
var filesize = file.ContentLength;
var contenttype = file.ContentType;
var FilePath = Server.MapPath("/Uploads");
string SavedFileName = Path.Combine(FilePath, filename);
file.SaveAs(SavedFileName);
newFile.FileName = filename;
newFile.FileSize = filesize;
newFile.FileType = filetype;
newFile.ContentType = contenttype;
newFile.FilePath = SavedFileName;
newFile.Description = model.Description;
newFile.Credit = model.Credit;
newFile.DateUploaded = DateTime.Now;
FormsIdentity identity = (FormsIdentity)User.Identity;
int nUserID = Int32.Parse(identity.Ticket.UserData);
newFile.Uploader = nUserID;
db.Media.Add(newFile);
db.SaveChanges();
//return RedirectToAction("Admin", "Index");
//Save file content goes here
}
if (isSavedSuccessfully)
{
return Json(new { Message = "File saved" });
}
else
{
return Json(new { Message = "Error in saving file" });
}
}
return View();
}