Context:
I want a user to only update one part [AppStatus] of an entry. However, when I test it, I get the error mentioned in the subject. I've seen similar questions asked, and tried doing some of the steps they outlined (using CASCADE for the FK, for instance). But it didn't work. So it's probably something in the code that I messed up with. I thought maybe, if I adjust the Bind to only include [AppStatus] that would do it, but that didn't work either.
The error throws on two different FKs [StudentID] and [JobPostingID].
Code:
Controller:
public ActionResult Edit([Bind(Include = "ApplicationID,StudentID,JobPostingID,Resume,AppStatus")] Application application)
{
if (ModelState.IsValid)
{
db.Entry(application).State = EntityState.Modified;
db.SaveChanges();
return RedirectToAction("Index");
}
ViewBag.StudentID = new SelectList(db.Students, "StudentID", "FirstName", application.StudentID);
ViewBag.JobPostingID = new SelectList(db.JobPostings, "JobPostingID", "Position", application.JobPostingID);
return View(application);
}
View:
<div class="form-horizontal">
<h4>Application</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ApplicationID)
<div class="form-group">
@Html.LabelFor(model => model.Student.FirstName, "FirstName", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DisplayFor(model => model.Student.FirstName)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.JobPosting.Position, "Position", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DisplayFor(model => model.JobPosting.Position)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.AppStatus, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EnumDropDownListFor(model => model.AppStatus, "--Update Application Status--", new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.AppStatus, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Save" class="btn btn-default" />
</div>
</div>
</div>
}