Update Image - It return Image file null.

Apr 22 2021 6:33 AM
Here is my code. ' If ' condition is false it go to the else part.  
[HttpPost]
public ActionResult DetailsEdit(EmployeeData___TBL e, HttpPostedFileBase ImageFile)
{
if (e.ImageFile != null)
{
string filename = Path.GetFileNameWithoutExtension(e.ImageFile.FileName);
string extension = Path.GetExtension(e.ImageFile.FileName);
HttpPostedFileBase postedfile = e.ImageFile;
int length = postedfile.ContentLength;
if (extension.ToLower() == ".jpg" || extension.ToLower() == ".jpeg" || extension.ToLower() == ".png")
{
if (length <= 1000000)
{
filename = filename + extension;
e.ProfileImage = "~/images/" + filename;
filename = Path.Combine(Server.MapPath("~/images/"), filename);
e.ImageFile.SaveAs(filename);
db.Entry(e).State = EntityState.Modified;
// int a = db.SaveChanges();
db.SP_UpdateUserInfo(e.UserId,e.Name, e.EmailID, e.PhoneNo, e.Address, e.ProfileImage);
//TempData["UpdateMessage"] = "<script>alert('Data Updated Successfully.')</script>";
ModelState.Clear();
return View();
}
 
 
 

Answers (6)