title: How to populate dropdownlist dynamically in mvc3 from two tables?
body: <p>I have created mvc3 application.
  where using EF to populate dropdownlist from tables.</p>
  
  <p>now I have <code>two dropdownlists</code> on my <code>index.cshtml</code> each populating from different tables.</p>
  
  <p>code index.cshtml:</p>
  
  <p>i have taken model as entity as it is having both my tables <code>table1</code> and <code>table2</code></p>
  
  <p><code>@model Mapping.Models.mydataEntities1</code></p>
  
  <p>but problem is here i'm not able to select values from both tables. :(</p>
  
  <p>like following code is for only working when i give 
  model <code>@model Mapping.Models.table1</code></p>
  
  <p>but need to select values into two dropdown from different tables</p>
  
  <pre><code>@using (Html.BeginForm())
  {
      @Html.DropDownListFor(
          x =&gt; x.CategoryId, 
          new SelectList(Model.Categories, "Value", "Text"),
          "-- Select category --"
      )
      &lt;input type="submit" value="OK" /&gt;
  }
  </code></pre>
  
  <p>How can i do this?</p>
  
  <p>I have used EF</p>
  
  <pre><code> public partial class mydataEntities1 : DbContext
      {
          public mydataEntities1()
              : base("name=mydataEntities1")
          {
          }
  
          protected override void OnModelCreating(DbModelBuilder modelBuilder)
          {
              throw new UnintentionalCodeFirstException();
          }
  
          public DbSet&lt;table1&gt; table1 { get; set; }
          public DbSet&lt;table2&gt; table2 { get; set; }
      }
  }
  </code></pre>