I have this scenario. I have 10 checkboxes that need to be generated(this list could grow and comes from the database).
Now a user may only have 3 of the 10. I want to always show all 10 checkboxes to the user but only check the ones they have.
I am unsure how my viewmodel and page should look like? I am unsure which html helper to be using. If I need a property(bool) for each of the values in the database showing which value they have.
It my database I don’t have a bit value showing if they have it or not. I have a many to many relationship. A user can have many features and a feature can have many users.
Build view models to describe your
UserandFeatureobjects. Then, you could use an editor template to display the checkbox.I said build, so do that in your controller, view model factory or service. The
Featureinstances are hard-coded here, but you’d want to retrieve them from the db:You can use subsequent actions with
UserFeatureViewModelparameters for updating, etc.Finally, the editor template in
~/Views/User/EditorTemplates/FeatureViewModel.cshtmlwould inherit aFeatureViewModeland use theHtml.CheckBoxForhelper:In your form (the “parent” view), use the
EditorForhelper to render the partial