TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
-------
NA
213
6.9k
uploaded image not display in mvc
Sep 22 2020 7:20 AM
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)
{
<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
Reply
Answers (
7
)
Get ID of recently created User Role using Identity .net core 2.0
shopping card, invoicing and payment checkout