开发者

User and ROles (how can i handle this?)

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜