I have a bunch of checkboxes that are used for the user to specify which columns they want to see on a grid:
At the moment, each checkbox has it's own key (which is essentially it's label name) and is declared like this in my view:
@Html.CheckBox(column.Key,
(Request.Form[column.Key] == null ? true :
Request.Form[column.Key].Contains("true")),
new { @class = "columnSelector" })
@Html.Label(column.HeaderText)
The issue is that I have to get the values from the form collection in my action, as otherwise I would have to have a bool
parameter for every column selector checkbox. Alternatively, I thought I could name them all 'columnselection' or something and then it would be passed to my action as an array of values, however then I lose the context of the value since I don't have the column key.
I don't want to create a viewmodel with a property for each checkbox as this functionality is used on other screens with different columns and I would like to keep it generic.
Any thoughts on how I could achieve this column selection stuff in a clean and simple way?