Asp.net 应用程序用户和控制器的外键
我也有类似的问题。在我的模型中建立关系后,我在控制器(创建和编辑)中出错。我尝试了一些方法,但似乎没有任何方法能解决问题。有什么想法吗?谢谢 型号:Asp.net 应用程序用户和控制器的外键,asp.net,entity-framework,asp.net-mvc-3,asp.net-identity,Asp.net,Entity Framework,Asp.net Mvc 3,Asp.net Identity,我也有类似的问题。在我的模型中建立关系后,我在控制器(创建和编辑)中出错。我尝试了一些方法,但似乎没有任何方法能解决问题。有什么想法吗?谢谢 型号: public class JbsTest{ public int Id { get; set; } public string Description { get; set; } public double Duration { get; set; } public int ProjectId { get; set; } public virt
public class JbsTest{
public int Id { get; set; }
public string Description { get; set; }
public double Duration { get; set; }
public int ProjectId { get; set; }
public virtual Project Project { get; set; }
public string UserId { get; set; }
[ForeignKey("UserId")]
public virtual ApplicationUser User { get; set; }
}
控制器:
public ActionResult Create()
{
ViewBag.ProjectId = new SelectList(db.Projects, "Id", "Name");
ViewBag.UserId = new SelectList(*db.ApplicationUsers*, "Id", "Name");
return View();
}
此行显示错误:
ViewBag.UserId = new SelectList(*db.ApplicationUsers*, "Id", "Name");
ApplicationDbContext类:
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext()
: base("DefaultConnection", throwIfV1Schema: false)
{
}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
public System.Data.Entity.DbSet<TestProject5.Models.JbsTest> JbsTests { get; set; }
}
public class ApplicationDbContext:IdentityDbContext您是否尝试过:ViewBag.UserId=new SelectList(db.Users,“Id”,“Name”)代码>?尝试过,不起作用。。