It's hard for me to try to figure out what I need to do to get this to work. I am learning ASP.NET MVC CodeFirst with EF. If I create a model, I can simply add a controller for this model and add scaffolding to create views that automatically take care of CRUD. But now I have two models: Project and Category. They have many different relationships, and the database is correctly designed using an associative table without creating a separate model for it. Code for models is ....
public class Project { public int ProjectId { get; set; } public string Title { get; set; } public string Description { get; set; } public string Testimonial { get; set; } public virtual ICollection<Image> Images { get; set; } public virtual ICollection<Category> Categories { get; set; } public Project() { Categories = new HashSet<Category>(); } } public class Category { public int CategoryId { get; set; } public string Name { get; set; } public ICollection<Project> Projects { get; set; } public Category() { Projects = new HashSet<Project>(); } }
So, I add my controllers and make scaffolding. I enter and create my categories very well. But when it comes to my project / creation, I would like to make all categories appear as checkboxes. In addition, I would like to make sure that at least one category is selected before you can submit a form to create a project. How should I do it?
source share