public ActionResult Attendance(FormModel form, int id)
{
ViewBag.studentname = new SelectList(db.Students, "StudentID", "Full_Name");
ViewBag.studentID = new SelectList(db.Students, "StudentID", " StudentID");
ViewBag.instructorID = new SelectList(db.Instructors, "InstructorID", "Name");
ViewBag.csID = id;
var attendances = db.Attendances;
return View(attendances.ToList());
}
Here i save the id into a viewbag to use later:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Attendance([Bind(Include = "AttendanceID,csID,InstructorID,StudentID")] Attendance attendance)
{
try
{
if (ModelState.IsValid)
{
attendance.csID = ViewBag.csID;
db.Attendances.Add(attendance);
db.SaveChanges();
//ViewBag.msg = "Instructor Added";
return RedirectToAction("Attendance");
}
return View(attendance);
}
catch
{
return View(attendance);
}
}
}
}
Over here i am trying the set the csid to the same value as the viewbag. When i debug it in the GET i get the int id but it isnt saving into the post when i debug it it says null in in both methods