0

"Object reference not set to an instance of an object."

[HttpPost]
        public ActionResult Create(AdulLiteracyTeachers adulliteracyteachers, HttpPostedFileBase[] files)
        {
            foreach (HttpPostedFileBase file in files)
            {
                string path = System.IO.Path.Combine(Server.MapPath("~/App_Data"), System.IO.Path.GetFileName(file.FileName));
                file.SaveAs(path);
            }
            if (ModelState.IsValid)
            {
                db.AdulLiteracyTeachers.Add(adulliteracyteachers);
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            ViewBag.DistID = new SelectList(db.Districts, "DistID", "DistName", adulliteracyteachers.DistID);
            return View(adulliteracyteachers);
        }

here is my view :

<p>
<label for="file">Upload Image:</label>
<input type="file" name="files" value="" multiple="multiple"/>

    <input name="Upload" type="submit" value="Create" />
</p>

On create button I got this error in MVC 4

Steven V
  • 16,357
  • 3
  • 63
  • 76

0 Answers0