mercredi 3 octobre 2018

ASP.NET MVC Update entity database on checkbox, passing in checkbox name

I have a "to do list" where the tasks (assignments) are stored as records in a database. One of the elements in the Assignment model is Complete. The page outputs all of the values in the Assignments (List<Assignment>) table using a for loop, along with a checkbox on the end.

@using (var ctx = new AssignmentContext())
        {
            var assignmentList = ctx.Assignments.ToList();
            foreach (Assignment assignment in assignmentList)
                <tr name ="@assignment.AssignmentId">
                    <td>@assignment.CourseName</td>
                    <td>@assignment.AssignmentName</td>
                    <td>@assignment.DueDate</td>
                    <td>@assignment.Value</td>
                    <td>@Html.CheckBox()</td>
                </tr>
        }

I want to change the state of the bool Assignment.Complete in the database on the click of the checkbox. I am pretty new to web development and the mixing of HTML and C# is what confuses me here. How do I have a onClick call a controller function and when I do, how do I pass it the specific row after the for loop has already ran. Do I NEED JS here?




Aucun commentaire:

Enregistrer un commentaire