【问题标题】:How to use checklistbox to update roles in account in mvc3如何使用复选框更新 mvc3 中帐户中的角色
【发布时间】:2013-08-30 23:44:58
【问题描述】:

我有任何型号

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。

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

【问题讨论】:

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


    【解决方案1】:

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

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

    在您的 ViewModel 中将其用作列表,将其传递给您的 View 并使用它进行显示,当您提交表单时,您可以通过在您的 ViewModel 中查看每条记录的 IsSelected 布尔值来检查哪些角色被检查在您的 SelectionRole 列表中。

    【讨论】:

      猜你喜欢
      • 2018-08-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-03-25
      • 2018-11-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多