I have a dynamic list of 10-25 strings and would like to present them as checkboxes in an ASP.NET MVC application. What’s the easiest way to do this? Do I have to create a list of ViewModel structures that pair booleans with strings? After a form post, I want to submit the checked values and resolve them to the list of strings again on the server side.
Thanks!
That would indeed be the best way and what I would recommend you:
Model:
Controller:
View (
~/Views/Home/Index.cshtml):and finally the editor template which will be rendered for each element of your model (
~/Views/Home/EditorTemplates/MyViewModel.cshtml):