Looking for some guidance on this issue (below is a parallel example):
I have a view in which I need to display a list of basic user information (e.g. First Name/Last Name) per row. In addition, I need to provide a list of check boxes for that represent permission levels for each user. The list of possible permissions is the same for everyone; however, needs to be dynamically driven by the database since different permission sets may be added or removed.
So…I have a list of users, and a common yet variable list of permissions that needs to be tracked per user.
What’s the best way to manage this from an object bind standpoint in a ASP.Net view?
I’ve solved a similar scenario using EditorTemplates
You could have a Users collection in the AssignPermissionViewModel, and a Permission collection in each user (UserModel). Then in your AssignPermission view, you should render the users editor:
And inside the user editor template you should render the permissions template:
This way you avoid having foreach loops all over your AssignPermission view, and you could re-use any editor in another view… (although these are very specific)
NOTE: It would be more appropriate to use a display template instead of an editor template to display the users information, since you’re not going to edit any user in this view, check this out: ASP.NET MVC 3 – Partial vs Display Template vs Editor Template