如何使用checkedlistbox更新mvc3中的帐户角色

时间:2013-08-28 03:14:03

标签: asp.net-mvc-3 checkboxlist checklistbox

我有任何模型

public class Account
    {
        [Key]
        public int AccountID { get; set; }

        public string UserName { get; set; }

        public string Password { get; set; }

        public string FullName { get; set; }
}

并且

public class Role
{
    [Key]
    public int RoleID { get; set; }
    public string RoleKey { get; set; }
    public string RoleName { get; set; }

}

并且

public class AccountRole
{
    [Key]
    public int ID { get; set; }
    public int AccountID { get; set; }
    public string Role { get; set; }

}

我想使用一个视图更新帐户和列表角色来列出复选框。当我签入复选框,然后将角色插入到AccountRole。

请告诉我如何创建我的视图。

1 个答案:

答案 0 :(得分:0)

为角色+布尔选择

创建持有者
public class SelectionRoles
{
   public bool IsSelected { get; set;}
   public Role OneRole { get; set; }
}

在ViewModel中将其作为List使用,将其传递给View并将其用于显示,当您提交表单时,您可以通过在IsSelected布尔值中查看ViewModel来检查控制器中哪些角色已经过检查在您的SelectionRole列表中。