How can I bind checkboxes to a viewmodel in mvc3

后端 未结 2 752
天涯浪人
天涯浪人 2021-02-15 03:14

I\'m really struggling to wrap my head around this:

I have a UserModel and a UserRoleModel:

    public class UserModel
{
    [Required]
    [Display(Name         


        
2条回答
  •  醉话见心
    2021-02-15 03:43

    As Rob mentioned in the previous answer all the Selected properties will be False. I used this piece of code to cover that.

    AllRoles  = Roles.GetAllRoles().Select(r => new RoleViewModel()
    {
         Name = r,
         Selected = Roles.GetRolesForUser(uvm.UserProfile.UserName).Contains(r) ? true : false
    });
    

提交回复
热议问题