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 7994695
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:11:59+00:00 2026-06-04T14:11:59+00:00

I’ve created an MVC 3 Razor application that manages Projects, and should manage Sections

  • 0

I’ve created an MVC 3 Razor application that manages Projects, and should manage Sections within those Projects.

So, I’ve made a model Projects.cs, controller ProjectsController, and got myself a Projects.sdf data table. Works just fine

Then I’ve added same for Sections, but Sections should have a field named projectID (made it of course) that is connected (joined) with ID in Projects.sdf; also, I need it to be able to be sorted by projectID, and from a DropDown

For example: Using DropDown to alter the table data. If lets say I select project1 from Project list, I want the list to show all Sections within that Project along with CRUD.

I’ve tried several things but none worked so far, I know how to do this in regular application but not in MVC so I beg for some assistance. Also tried to add DropDown in Sections view and getting it to populate from Project model data, but no good at all.

So I need help on how to do this 🙁

Please, and thank you.

Addition

Project has many Sections, and yes I’m using EF, but as I said not too experienced with it.

as for data context
this is Project

namespace MyProject.Models
{
    public class Projects
    {
        public int ID { get; set; }
        public string projectName { get; set; }
        public string shortDesc { get; set; }
    }

    public class ProjectsDBContext : DbContext 
    {
        public DbSet<Projects> Projects { get; set; }        
    }
}

this is Section

namespace MyProject.Models
{
    public class Sections
    {
        public int ID { get; set; }
        public int projectID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }

    public class SectionsDBContext : DbContext 
    {
        public DbSet<Sections> Sections { get; set; }
    }
}

Addition 2

So I made a model named MyProjectModels.cs

namespace MyProject.Models 
{
    public class Project
    {
        public int ID { get; set; }
        public string Name { get; set; }
        public string Description { get; set; }
    }

    public class Section
    {
        public int ID { get; set; }
        public int projectID { {get; set;}
        public string Name { get; set; }
        public string Description { get; set;}
    }
}

So basically I’m kinda figuring it out. Please let me know if this is ok for models or do I need to put them in separate files? Also, How should i declare context from this point, a hint would be enough 🙂

Thank you


This is the way I have done it. It displays properly but i have NO idea how to utilize it, for example to show different values in a table…

<select id="select1" name="select1">
        @foreach (var item in Model.Enrollments)
        {
        <option value=@Html.DisplayFor(modelItem => item.Course.Title)>@Html.DisplayFor(modelItem => item.Course.Title)</option>
        }
</select>

by different values in table i meant, when i select different enrollment in this case. i would like to show different values in table.

  • 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-06-04T14:12:00+00:00Added an answer on June 4, 2026 at 2:12 pm

    Do you really need to have different dbcontexts? If it is one sdf file then I’m guessing not and your dbcontext should look like

    namespace MyProject.Models
    {
        public class DatabaseContext: DbContext 
        {
             public DbSet<Projects> Projects { get; set; } 
             public DbSet<Sections> Sections{ get; set; }         
        }
    }
    

    then in your projects model you would have a property for sections

    namespace MyProject.Models
    {
        public class Projects
        {
            public int ID { get; set; }
            public string projectName { get; set; }
            public string shortDesc { get; set; }
            public Sections section { get; set; }
        }
    }
    

    and your sections would just need an id field

    namespace MyProject.Models
    {
        public class Sections
        {
            public int ID { get; set; }
            public int projectID { get; set; }
            public string Name { get; set; }
            public string Description { get; set; }
        }
    }
    

    As long as your sections class has a primary key field called ID or the id property flagged as the primary key then EF will make the logical leap that Projects has a foreign key of section in the table structure. your projects model will then have access to the section object. Biggest hurdle I had with EF was overthinking the database side of things.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post

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.