繁体   English   中英

如何使用清单框更新MVC3中帐户中的角色

[英]How to use checklistbox to update roles in account in mvc3

我有模特

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中的角色。

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

为角色+布尔IsSelected创建一个持有人

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

在ViewModel中以列表的形式使用它,将其传递给View并用于显示,当您提交表单时,可以通过在ViewModel中的IsSelected布尔值中查看SelectionRole中的每个记录,来检查控制器中哪些角色已被检查清单。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM