In my view, I'd like to add a User to a role using checkboxes. I list all the roles then check two or three to add the user to that role. How do I handle t开发者_Go百科his?
You could do something like this in your post...
[HttpPost]
public ActionResult UserDetails(UserClass user, bool admin, bool superAdmin, bool GodRole)
{
MembershipUser muser = Membership.GetUser(user.UserName);
if (admin)
Roles.AddUserToRole(muser.UserName, "admin");
if (superAdmin)
Roles.AddUserToRole(muser.UserName, "superAdmin");
if (GodRole)
Roles.AddUserToRole(muser.UserName, "GodRole");
return View();
}
Hope this helps...
精彩评论