我有一些与多对多关系的问题,保存了创建视图的结果.
我想为新的用户配置文件创建一个创建页面,该配置文件有一个清单,可以让他们选择课程(多对多关系).我的视图从Courses数据库中获取记录,并使用复选框显示所有记录.
一旦用户发布数据,我想更新我的userprofile模型,以及courses多对多关系.那是我遗漏的代码!
我是MVC的新手,我一直在研究,但我还没有做到.
我遵循这个例子:http: //www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/updating-related-data-with-the-entity-framework-in-an- ASP净MVC应用程序
这是模型:
public class UserProfile
{
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Courses> usercourses { get; set; }
}
public class Courses
{
public int CourseID { get; set; }
public string CourseDescripcion { get; set; }
public virtual ICollection<UserProfile> UserProfiles { get; set; }
}
public class UserProfileDBContext : DbContext
{
public DbSet<UserProfile> UserProfiles { …Run Code Online (Sandbox Code Playgroud) asp.net-mvc many-to-many entity-framework razor asp.net-mvc-3