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 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions01ForumsTop experts
Arun PottiAnswers in the forums20answers02
Tahir AnsariAnswers in the forums5answers03
Kamlesh KumarAnswers in the forums5answers04
Sam HobbsAnswers in the forums4answers05
Željko PerićAnswers in the forums3answersFull leaderboard →
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Sachin SinghRank #66 · 26.2K reputationPosted Sep 22, 2020, 5:47 AM EDT
Pankajkumar PatelRank #181 · 13.4K reputationPosted Sep 22, 2020, 5:25 AM EDT
Pankajkumar PatelRank #181 · 13.4K reputationPosted Sep 22, 2020, 4:59 AM EDT
-------Rank #8,369 · 223 reputationPosted Sep 22, 2020, 5:04 AM EDT
Nisha RegilRank #1,956 · 748 reputationPosted Sep 22, 2020, 5:34 AM EDT
-------Rank #8,369 · 223 reputationPosted Sep 22, 2020, 7:24 PM EDT
Sachin SinghRank #66 · 26.2K reputationPosted Sep 22, 2020, 11:41 PM EDT