public ActionResult Create(Job job, HttpPostedFileBase upload)
{
if (ModelState.IsValid)
{
string path = Path.Combine(Server.MapPath("~/Uploads"), upload.FileName);
upload.SaveAs(path);
job.JobImage = upload.FileName;
db.Jobs.Add(job);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.CategoryId = new SelectList(db.Categories, "Id", "CategoryName", job.CategoryId);
return View(job);
}
This is the code, What is the solution for this problem?
- the code of the problem of uploading a picture, I have tried several solutions but it did not work, like replacing the <<if(ModelState.IsValid)>> with if <<(upload.ContentLength > 0 )>> but it didn't work.
- the problem occurs from the line <<string path = Path.Combine(Server.MapPath("~/Uploads"), upload.FileName);>> I am not able to upload pictures. What should I do to fix this problem?