开发者

User and ROles (how can i handle this?)

开发者 https://www.devze.com 2023-04-07 03:27 出处:网络
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

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...

0

精彩评论

暂无评论...
验证码 换一张
取 消