I have a collection of "permissions". Each permission would have three properties: Id, Name, and HasPermission. So as an example, consider the following object:
public class AccessPerm
{
int PermId {get;set;}
string PermName {get;set}
bool HasPerm {get;set;}
}
public class UserProfile
{
Collection<AccessPerm> UserPerms {get;set;}
}
So I want to use the CheckBoxFor helper to create checkboxes so that one can set the user's permissions. If you check the box, then HasPerm should be true. If you uncheck it, HasPerm should be false. The problem I am having is I don't see a way to bind both the PermId and the HasPerm properties to the checkbox. I used the following code to bind the HasPerm property, but it is not useful because I don't know the PermId.
<%
for(int ix=0; ix< Model.UserProfile.Perms.Count; ix++)
{
Html.CheckBoxFor(model => model.UserProfile.Perms[ix].HasPerm);
}
%>
This code does indeed bind HasPerm, and the value is correct. However, since I don't have the id, I can't do anything with the value. Please advise.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…