当我尝试将图片添加到数据库时,我收到错误
" InvalidOperationException:一个依赖属性 ReferentialConstraint映射到存储生成的列。柱: '作业ID'"
我认为它试图将信息保存在job
表中,而不是jobPic
表中。我不确定如何解决这个问题。任何帮助将不胜感激。
// GET: jobPics/Create
public ActionResult Create()
{
ViewBag.JobID = new SelectList(db.jobPics, "JobID", "Description");
return View();
}
// POST: jobPics/Create
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "JobID,Before,After")] jobPic jobPics)
{
if (ModelState.IsValid)
{
db.jobPics.Add(jobPics);
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.JobID = new SelectList(db.jobPics, "JobID", "Description", jobPics.JobID);
return View(jobPics);
}