Imagine a page which uses checkboxes to keep track of mailing list subscriptions about pets:
cats-list ( )
dogs-list (*)
birds-list ( )
horses-list (*)
I use ASP.NET MVC's Html.Checkbox extension method in a loop (not shown):
<%= Html.Checkbox("subscriptions[" + i +"]", item.subscribed, item.listName) %>
"i" is the iteration variable in the loop. Using this convention allows my controller action to model bind subscriptions[i]
to a List<string>
which then contains a list of mailing list names to subscribe to.
How can I keep track of what's not checked? For example, if a user unchecks "dogs-list" to unsubscribe from that list, how can I tell? I'll only get "false" back from the hidden form field.
EDIT: The only solution which comes to mind is for the controller action to unsubscribe from all mailing lists, and then resubscribe to lists contained in the List<string>
from the checkboxes. That's not ideal though.