MVC 4 NULLReferenceException未被用户处理

时间:2014-04-16 17:53:25

标签: asp.net-mvc asp.net-mvc-4

“对象引用未设置为对象的实例。”

[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);
        }

这是我的观点:

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

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

在创建按钮上我在MVC 4中收到此错误

0 个答案:

没有答案