I am trying to add a checkbox so I can selects a row from my list and from there use that row to generate a letter. I was wondering how I would be able to add a checkbox and bind it to the data I have tried a few ways using something similar to:
checkbox(m => m[i].Lesson)
However it would never accept the i in brackets and come up with an error. below is the layout of my index for the lessons model currently.
Here is the Lessons Index:
@model IEnumerable<FinalMusicApp.Models.Lesson>
@{
ViewBag.Title = "Index";
}
<h2>Lessons</h2>
<p>
@Html.ActionLink("Create New", "Create")
</p>
@using (Html.BeginForm("Index", "Students", FormMethod.Get))
{
//Search options
<b>Search Options: </b> @Html.RadioButton("Option", "Instrument")<text>Instrument</text>@Html.RadioButton("Option", "Tutor")<text>Tutor</text>@Html.RadioButton("Option", "Term")<text>Term</text>@Html.TextBox("Search")
<input type="submit" name="submit" value="Search" />
}
<form method="post">
<table class="table">
<tr>
<th>
@Html.DisplayNameFor(model => model.IsChecked)
</th>
<th>
@Html.DisplayNameFor(model => model.LessonDate)
</th>
<th>
@Html.DisplayNameFor(model => model.LessonTime)
</th>
<th>
@Html.DisplayNameFor(model => model.Duration.TimeTaken)
</th>
<th>
@Html.DisplayNameFor(model => model.Instrument.InstrumentName)
</th>
<th>
@Html.DisplayNameFor(model => model.Letter.Paid)
</th>
<th>
@Html.DisplayNameFor(model => model.Student.FullName)
</th>
<th>
@Html.DisplayNameFor(model => model.Tutor.TutorName)
</th>
<th>
CRUD
</th>
<th>
Make a letter
</th>
</tr>
@foreach (var item in Model)
{
<tr>
<td>
@Html.CheckBoxFor(modelItem => item.IsChecked)
</td>
<td>
@Html.DisplayFor(modelItem => item.LessonDate)
</td>
<td>
@Html.DisplayFor(modelItem => item.LessonTime)
</td>
<td>
@Html.DisplayFor(modelItem => item.Duration.TimeTaken)
</td>
<td>
@Html.DisplayFor(modelItem => item.Instrument.InstrumentName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Letter.Paid)
</td>
<td>
@Html.DisplayFor(modelItem => item.Student.FullName)
</td>
<td>
@Html.DisplayFor(modelItem => item.Tutor.TutorName)
</td>
<td>
@Html.ActionLink("Edit", "Edit", new { id = item.LessonId }) |
@Html.ActionLink("Details", "Details", new { id = item.LessonId }) |
@Html.ActionLink("Delete", "Delete", new { id = item.LessonId })
</td>
<td>
@Html.ActionLink("Generate Letter", "Create", "Letters")
</td>
</tr>
}
</table>
</form>