I am trying to display uploaded image in list page but not work
I know this is very basic thing but I am struggling with last two-three hour
HomeController.cs
- [HttpGet]
- public ActionResult EmployeeCreate()
- {
- return View();
- }
-
- [HttpPost]
- public ActionResult EmployeeCreate(emp emp, HttpPostedFileBase ePhoto)
- {
- if (ePhoto != null && ePhoto.ContentLength > 0)
- {
- try
- {
- var fileName = Path.GetFileName(ePhoto.FileName);
- var rondom = Guid.NewGuid() + fileName;
-
- var path = Path.Combine(HttpContext.Server.MapPath("~/data/"), rondom);
- if (!Directory.Exists(HttpContext.Server.MapPath("~/data/")))
- {
- Directory.CreateDirectory(HttpContext.Server.MapPath("~/data/"));
- }
- ePhoto.SaveAs(path);
- emp.ePhoto = path;
-
- _dbfltEntities.emps.Add(emp);
- _dbfltEntities.SaveChanges();
- return RedirectToAction("EmployeeList");
- }
- catch(Exception ex)
- {
- throw ex;
- }
- }
- return View(emp);
- }
-
- public ActionResult EmployeeList()
- {
- return View(_dbfltEntities.emps.ToList());
- }
employeelist.cshtml
- @foreach (var item in Model)
- {
- <tr>
- <td>@item.empid</td>
- <td>
- @item.ename
- </td>
- <td>
- @item.edesignation
- </td>
- <td>
- @item.eexperience
- </td>
- <td>
- <img src="@Url.Content(@item.ePhoto)" style="width:50px;height:50px;" alt="Uploaded Image" />
- @item.ePhoto
- </td>
when I copy the path and paste in new tab then show the image
but in list page not shown image
please help