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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:29:09+00:00 2026-05-23T09:29:09+00:00

I made a simple mvc 3 web site. It’s working fine but the database

  • 0

I made a simple mvc 3 web site. It’s working fine but the database and classes are messy because I needed to make dropdownlists and I have no idea how to implement the drowdownlists using a different style.

Here’s how things look like:

public class Departments
{
   public int ID {get; set;}
   ...
}

public class Users
{
   public int ID {get; set;}
   ...
   public Department Dept {get; set;}
   public List<Department> DeptList {get; set;}
   public string SelectedDept {get; set;}       
}

then I used DropDownListFor helper. I’m new on this code first thing, sadly. So, now I got these 2 extra unnecessary columns along in the database. Any other way to do this cleaner/better?

  • 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-23T09:29:10+00:00Added an answer on May 23, 2026 at 9:29 am

    Your class should look like this

    public class Users
    {
       public int ID {get; set;}
       ...
       public virtual int DeptId {get; set;}
        [ForeignKey("DeptId")]
       public virtual Department Dept {get; set;}
    
    }
    

    Then in your MVC .NET Controller you perform a query to populate List DeptList.
    DeptList can be stored in ViewBag.DeptList or as a property of the Model you return to the view.

    string SelectedDept is not needed. When you use DropDownListFor helper it will automatically set Users.DeptId for you.

    Also you may want to consider renaming “Users” to “User” =)

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

Sidebar

Related Questions

I am playing with MVC and I made a simple site. I have an
I made a simple silverlight web application that just has one button filling up
I just installed Ubuntu 8.04 and Eclipse. I made a very simple Hello World
I have a simple software that is made in Delphi 7, and it crashes
Today we faced a quite simple problem that were made even simpler by the
Heavy emphasis on simple. I've never made an installer and I'd rather not have
I'm trying to add simple login page to ASP.NET MVC app. I actually use
I created an ASP.NET MVC 2.0 Application. It ran fine at first test and
I have started converting my simple website to ASP.NET MVC, just to mess around
For a school project I'm making a simple Job Listing website in ASP.NET MVC

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.