I am trying to build an application that will allow a teacher to enter class attendance within a web application. I have gotten it to display the students in the specified class along with a drop down list that is populated with the possible attendance choices. When the instructor clicks the save attendance button, the returned values is just a list of all the chosen values like attend_detail=PRESENT&attend_detail=PRESENT&attend_detail=ABSENT&attend_detail=TARDY&attend_detail=ABSENT&attend_detail=PRESENT&attend_detail=PRESENT&attend_detail=UNEX+AB. It has each value selected for each student, but I have no way to know who had which status.
Here is the View that shows the students.
@model IEnumerable<RLCAttendanceWebAppNoOauth.Models.student_list>
@{
ViewBag.Title = "ClassList";
}
<h2>ClassList</h2>
<p>@ViewBag.attend_date</p>
<p>@ViewBag.year</p>
<p>@ViewBag.term</p>
@using (Html.BeginForm("SaveAttendance", "Schedule", FormMethod.Post))
{
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.ID)
</th>
<th>
@Html.DisplayNameFor(model => model.LAST_NAME)
</th>
<th>
@Html.DisplayNameFor(model => model.FIRST_NAME)
</th>
<th></th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.ID)
</td>
<td>
@Html.DisplayFor(modelItem => item.LAST_NAME)
</td>
<td>
@Html.DisplayFor(modelItem => item.FIRST_NAME)
</td>
<td>
<p>
@Html.DropDownList("attend_detail", null, "", new { id = item.ID })
</p>
</td>
</tr>
}
</table>
<input type="submit" value="Save Attendance" />
}
Here is the Model for student_list.
using System;
using System.Collections.Generic;
public partial class student_list
{
public string LAST_NAME { get; set; }
public string FIRST_NAME { get; set; }
public Nullable<System.DateTime> CHANGE_DATE { get; set; }
public string ACADEMIC_YEAR { get; set; }
public string ACADEMIC_TERM { get; set; }
public string ACADEMIC_SESSION { get; set; }
public string EVENT_ID { get; set; }
public string SECTION { get; set; }
public string ID { get; set; }
}
Here is the code from the controller that lists the students in the class.
public ActionResult ClassList(DateTime Attend_Date)
{
Session["attend_date"] = Attend_Date.ToShortDateString();
sp_rlc_lti_student_list_Result model = new sp_rlc_lti_student_list_Result();
var attend_detail = db.attend_detail
.OrderBy(q => q.CODE_VALUE_KEY)
.ToDictionary(q => q.CODE_VALUE_KEY, q => q.LONG_DESC);
ViewBag.attend_detail = new SelectList(attend_detail, "Key", "Value");
var year = Session["year"].ToString();
var term = Session["term"].ToString();
var event_id = Session["course_id"].ToString();
var section = Session["section"].ToString();
var classListQry = from c in db.student_list
where c.ACADEMIC_YEAR == year
& c.ACADEMIC_TERM == term
& c.EVENT_ID == event_id
& c.SECTION == section
& c.CHANGE_DATE > Attend_Date
select c;
return View(classListQry);
}
Here is the code from the controller that executes when the save button is clicked.
public ActionResult SaveAttendance()
{
ViewBag.message = "The attendance for the class was saved for: " + Session["attend_date"].ToString();
return View();
}
When the save button is clicked I need to be able to push the selected attendance for each student back to a database. The student_list model includes the student's unique ID, I just have not found a way to link the value selected in the drop down list to the student it was selected for.
What I have tried:
I am not exactly sure what to try at this point. I have looked for solutions online and either they are not out there or I am not asking the question correctly.