Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 3 如何使用复选框更新mvc3中帐户中的角色_Asp.net Mvc 3_Checkboxlist_Checklistbox - Fatal编程技术网

Asp.net mvc 3 如何使用复选框更新mvc3中帐户中的角色

Asp.net mvc 3 如何使用复选框更新mvc3中帐户中的角色,asp.net-mvc-3,checkboxlist,checklistbox,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 Account
    {
        [Key]
        public int AccountID { get; set; }

        public string UserName { get; set; }

        public string Password { get; set; }

        public string FullName { get; set; }
}

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


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

为一个角色创建一个持有者+一个布尔值

public class SelectionRoles
{
   public bool IsSelected { get; set;}
   public Role OneRole { get; set; }
}
在ViewModel中将其用作列表,将其传递给视图并用于显示,提交表单时,您可以通过查看ViewModel中SelectionRole列表中每个记录的IsSelected布尔值,在控制器中检查要检查的角色

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

}
public class SelectionRoles
{
   public bool IsSelected { get; set;}
   public Role OneRole { get; set; }
}