2013-03-24 71 views
1

我正在使用MVC4 Internet应用程序,并试图更改帐户模型以使用我的上下文。我似乎无法得到它的工作。我试图删除上下文,并在我的上下文中包含用户配置文件,我可以登录等,但当我通过用户id检查配置文件时,它会返回空值。更改用户上下文

public DbSet<FightCard> FightCards { get; set; } 
public DbSet<Fight> Fights { get; set; } 
public DbSet<Fighter> Fighters { get; set; } 
public DbSet<UserProfile> UserProfiles { get; set; } 

[Table("UserProfile")] 
public class UserProfile 
{ 
    [Key] 
    [DatabaseGeneratedAttribute(DatabaseGeneratedOption.Identity)] 
    public int UserId { get; set; } 
    public string UserName { get; set; } 

} 

当我尝试这样做:

public ActionResult Profile(int id) 
    { 
     UserProfile profile = uc.UserProfiles.Find(id); 
     ViewBag.Name = profile.UserName; 
    } 

我得到一个空值回报。任何人都知道如何在不同的环境下成功使用简单的会员资格?

回答

1

解决了它。但说实话,我并不确定是什么修复了它。这是我使用的链接,其中一部分解决了我的问题。

http://dansgreenshoes.com/2013/03/10/mvc4usertable/

+0

你使用哪一部分 – 2013-03-25 02:08:24

+0

刚刚从零开始,固定它。 – 2013-03-28 21:08:01