Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7436327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:13:20+00:00 2026-05-29T10:13:20+00:00

I am having a hard time trying to figure out what I need to

  • 0

I am having a hard time trying to figure out what I need to do to get this to work. I’m learning ASP.NET MVC CodeFirst with EF. If I make a model I can simply add a controller for that model and add scaffolding to create views that automatically take care of CRUD. But now I have two models, Project and Category. They have a many to many relationship and database is designed correctly with the associative table without having to make a separate model for it. The code for the models is this….

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 do the scaffolding. I go in and create my categories just fine. But when it comes to my Projects/Create view, I would like to make it so that all the categories are displayed as checkboxes. Also, I would like to ensure that at least one category is selected before being able to submit the form to create a project. How would I do this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:13:21+00:00Added an answer on May 29, 2026 at 10:13 am

    For an example of using check boxes in a similar scenario, see Adding Course Assignments to the Instructor Edit Page in this tutorial:

    http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/updating-related-data-with-the-entity-framework-in-an-asp-net-mvc-application

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a real hard time trying to figure out how to fix this
I am having one heck of a hard time trying to figure this out.
I'm having a hard time trying to figure out why this piece of code
I'm having a hard time trying to figure this out. Say I have the
I'm having a hard time trying to figure this out. I have a button_to
I'm having hard time trying to figure out how to auto-save user data in
I'm having a hard time trying to get hasMany to work in Grails 2.0.1
I am having a hard time trying to figure out when to use a
I am having a hard time trying to figure out if the following design
Having a really hard time trying to figure out a where in equivalent in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.