I am generating a number of checkboxes from a database and rendering them in my HTML. The functionality I would like is for the user to be able to select a number of the checkboxes, the userID of this user to be passed into a C# method which will run an algorithm and render another page. How can I pass this data to my algorithm effectively?
Here is my code so far :
@{
var db = Database.Open("mPlan");
var sql = "SELECT * from Users";
var result = db.Query(sql);
}
<form id="form" name="form" method="post" action="">
@{foreach (var user in result) {
<label for="username">@user.Username</label>
<input type="checkbox" name="@user" id="username" />
}
<button type="submit">Add</button>
</form>
The form should then pass the values for userId as a comma-seperated list.
To retrieve the list of ids you could do the following: