My file upload is not working. I want to upload images. I have already created the input type file in my view. Here is my code-
[HttpPost]
public ActionResult AddOrEdit(tbl_employee emp)
{
var getGender = db.tbl_gender.ToList();
SelectList list = new SelectList(getGender, "gender_type", "gender_type", emp);
ViewBag.genderList = list;
if (emp.employee_image != null)
{
string fileName = Path.GetFileNameWithoutExtension(emp.imageFile.FileName);
string extension = Path.GetExtension(emp.imageFile.FileName);
fileName = fileName + extension;
emp.employee_image = "~/Images/Employee/" + fileName;
fileName = Path.Combine(Server.MapPath("~/Images/Employee/"), fileName);
emp.imageFile.SaveAs(fileName);
}
if (emp.employee_id == 0)
{
db.tbl_employee.Add(emp);
db.SaveChanges();
return Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet);
}
else
{
db.Entry(emp).State = EntityState.Modified;
db.SaveChanges();
return Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet);
}
}
Here is my tbl_employee.cs
public long employee_id { get; set; }
public string employee_image { get; set; }
public HttpPostedFileBase imageFile { get; set; }
What is wrong here?