I am creating an ASP.Net application that displays records from a SQLite database and incorporating filter options that are built from the records that are coming in since I do not know what kind of data will be in the columns. I have the filter in place and will create the HTML form that will display the field value and how many records with that value there are. However I am not sure how to grab that data since as far as I am aware, the receiving method in the controller will expect a matching parameter for each variable (HTML form: value="bob", the receiving method in the controller takes a parameter such as string bob). My code for generating the HTML form is:
<div>
<text>Employment:</text> <br />
@foreach (var employment in Model.Employment)
{
<input type="checkbox" value="{@employment.Key}"/>@employment.Key <text>(@employment.Value)</text> <br />
}
<hr />
</div>
Since there could be, for instance, 15 different selection chosen, how would I grab all of the values that are generated? Additionally, there are about 5 more sections like this for filter options. Is it possible to transmit all selections as a dictionary like
<key,<key,value>>
and then parse through the nested dictionaries? The dictionaries would then hold the main category of filters(main key) and then each accepted filter option(parent's value/key) within that category with the a ture(for the parent's value's value).
Edit: Adding some addition code as requested. This is the class that represents an employee for a company:
public class MemberModel
{
public string ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Address { get; set; }
public string EmailAddress { get; set; }
public string PhoneNumber { get; set; }
public string Position { get; set; }
public string Department { get; set; }
public string StartDate { get; set; }
public string EndDate { get; set; }
public string EmploymentStatus { get; set; }
public string Shift { get; set; }
public string Manager { get; set; }
public string Photo { get; set; }
public string FavoriteColor { get; set; }
}
This might not be necessary for the implementation but made sense to me for building this app. This is a class that contains a list of all employees and dictionaries that I use for building the filter options:
public class TeamMembersModel
{
public Dictionary<string, int> Employment { get; set; }
public Dictionary<string, int> Position { get; set; }
public Dictionary<string, int> Shift { get; set; }
public Dictionary<string, int> Department { get; set; }
public Dictionary<string, int> Manager { get; set; }
public List<MemberModel> Employees { get; set; }
}
This code is a condensed version of how I build the form for filtering:
<form asp-action="" asp-controller="TeamMembers" method="get">
<!-- Department -->
<div>
<text>Department:</text> <br />
@foreach (var departments in Model.Department)
{
<input type="checkbox" value="@departments.Key" />@departments.Key <text>(@departments.Value)</text> <br />
}
<hr />
</div>
<!-- This is repeated for each dictionary in the TeamMembersModel class -->
<button type="submit" value="Filter">Filter</button>
</form>