I have a loop that creates a button for each entry. However, I need to set a dynamic id for the button in order to use it and know the selected entry upon button click.
My controller retrieves a list of entries from the database and using "ViewBag.List", I added the buttons. The list derrived from the database includes ID, Title and Description.
This is the view/ Index.cshtml
@model Exams.Models.subjects
@{
ViewBag.Title = "Subjects"
}
<h2> Current Subjects </h2>
<form method="post" action="@Url.Action("Submit")" >
<table>
@foreach(var subject in ViewBag.List){
<tr>
<td>
@subject.Title </br>
@subject.Desc
</td>
<td>
<button name="Submit"> Submit </button>
<td>
<tr>
}
</table>
Upon clicking the button, the next view must include "You just registered " + SubjectTitle
How should the subject Title be included? Knowing that simple ViewBag saves the SubjectTitle by reference