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;
- //image upload name + randomguid
- 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)
- {
-
@item.empid - @item.ename
- @item.edesignation
- @item.eexperience
"@Url.Content(@item.ePhoto)" style="width:50px;height:50px;" alt="Uploaded Image" />
- @item.ePhoto
when I copy the path and paste in new tab then show the image
but in list page not shown imageplease help7 Replies
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Sachin SinghPosted Sep 23, 2020, 3:41 AM
-------Posted Sep 22, 2020, 11:24 PM
Sachin SinghPosted Sep 22, 2020, 9:47 AM
Nisha RegilPosted Sep 22, 2020, 9:34 AM
Pankajkumar PatelPosted Sep 22, 2020, 9:25 AM
-------Posted Sep 22, 2020, 9:04 AM
Pankajkumar PatelPosted Sep 22, 2020, 8:59 AM