-1

使用简单的成员资格提供程序....和用户视图(将用户 ID 传递到)用户角色控制器

我的索引(用户角色)(ID 是用户控制器视图中 ActionLink 的用户 ID)

    public ActionResult Index([Bind(Prefix = "id")] int id)
    {
        var usr = db.UserRoles.Find(id);

        if (usr != null)
        {
            return View(usr);
        }

        return View();
        //return View(db.UserRoles.ToList());
    }

但我的模型是

[Table("webpages_UsersInRoles")]
public class UserRoles
{
    [Key]
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)]
    public int UserId { get; set; }
    public int RoleID { get; set; }

}

错误 在此处输入图像描述

谢谢

换句话说,它甚至不应该在寻找 UserProfiles_UserID .....?

我也得到了这个:堆栈跟踪:

 [SqlException (0x80131904): Invalid column name 'UserProfiles_UserId'.
 Invalid column name 'UserProfiles_UserId'.

我的数据库或模型中也没有这个字段;/我对它为什么要寻找它感到困惑?

4

1 回答 1

1

您可以使用以下代码将用户添加到角色:

 System.Web.Security.Roles.AddUsersToRole("user1", "user2", "user3", ... , "yourrolename");
于 2013-07-25T14:58:49.810 回答