我的文件上传无效。我想上传图片。 我已经在视图中创建了输入类型文件。 这是我的代码 -
[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);
}
}
这是我的tbl_employee.cs
public long employee_id { get; set; }
public string employee_image { get; set; }
public HttpPostedFileBase imageFile { get; set; }
这里有什么问题?