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

  • Home
  • SEARCH
  • 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 7780241
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:50:25+00:00 2026-06-01T18:50:25+00:00

I have created mvc3 application. where using EF to populate dropdownlist from tables. now

  • 0

I have created mvc3 application.
where using EF to populate dropdownlist from tables.

now I have two dropdownlists on my index.cshtml each populating from different tables.

code index.cshtml:

i have taken model as entity as it is having both my tables table1 and table2

@model Mapping.Models.mydataEntities1

but problem is here i’m not able to select values from both tables. 🙁

like following code is for only working when i give
model @model Mapping.Models.table1

but need to select values into two dropdown from different tables

@using (Html.BeginForm())
{
    @Html.DropDownListFor(
        x => x.CategoryId, 
        new SelectList(Model.Categories, "Value", "Text"),
        "-- Select category --"
    )
    <input type="submit" value="OK" />
}

How can i do this?

I have used EF

 public partial class mydataEntities1 : DbContext
    {
        public mydataEntities1()
            : base("name=mydataEntities1")
        {
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            throw new UnintentionalCodeFirstException();
        }

        public DbSet<table1> table1 { get; set; }
        public DbSet<table2> table2 { get; set; }
    }
}
  • 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-01T18:50:26+00:00Added an answer on June 1, 2026 at 6:50 pm

    I’m not an EF user, but assuming that your model is populated and works correctly
    the following code should works

    @Html.DropDownListFor(
        x => x.table1.CategoryId, 
        new SelectList(Model.table1.Categories, "Value", "Text"),
        "-- Select category --"
    )
    
    @Html.DropDownListFor(
        x => x.table2.CategoryId, 
        new SelectList(Model.table2.Categories, "Value", "Text"),
        "-- Select category --"
    )
    

    But I strongly reccomend you to create a ViewModel to expose your data to the View and not your domain entities or directly the repository.

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

Sidebar

Related Questions

I have created one MVC3 application. In which I'm selecting two Ids from two
I have an MVC3 application using NHibernate. I've created my own membership and role
I have created a simple application using MVC3 and the site is based on
I have created a web application using ASP.NET MVC3 in Visual studio (no SQL
I have created a web application in mvc3 and created two partial views one
I have created a web application in mvc3 and created two partial views one
i have created an mvc3 web application that uses forms based authentication. one part
I have created a sample MVC3 application for BookShop. I have a create action.
I just created a sample MVC3 application to learn validation. It is using DataAnnotations.
I've created a new site using mvc3 and now I'm getting closer to the

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.