2013-08-28 39 views
0

更新帳戶角色我有什麼型號如何使用checklistbox在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中的角色。

請告訴我如何創建我的視圖。

回答

0

創建持有者爲角色+一個布爾IsSelected

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

在您的視圖模型使用這個作爲一個列表,它傳遞給你的查看和使用它的顯示,當您提交表格,您可以檢查你的控制器通過在你的ViewModel中查看你的SelectionRole列表中每個記錄的IsSelected布爾值來檢查哪些角色。