Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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.
C#
@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.
C#
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.
C#
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.
C#
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.
Posted
Updated 4-Jun-19 8:58am

1 solution

c# - Return List<T> from view to controller in MVC 3 - Stack Overflow[^]

Use radio buttons. Simpler, IMO, since you have few choices.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900