title: Asp net MVC 5 and listbox with linq
body: <p>After several days of reading on how to fill a listbox with linq i am completely lost on what I have to do to make this work. I know I have to have a viewmodel or something like that but since i cannot reference 2 models in the same view I don t know what to do.</p>
  
  <p>this is the model i have</p>
  
  <pre><code>public class ABC
  {
      public int a { get; set; }
      public int b { get; set; }
      public int c { get; set; }
      public string d { get; set; }
      public string Type { get; set; }
      public int ID { get; set; }
  
      public class  ABCDBContext : DbContext
      {
          public DbSet&lt;ABC&gt; ABCs { get; set; }
      }
  }
  
  public class ABCModel
  {
      public string type{ set; get; }
      public List&lt;ABC&gt; ABCs { set; get; }
  }
  </code></pre>
  
  <p>The controller i know i am missing a lot of things but I don´t know how to fill the list with that linq query nor how to call this controller from the view without using beginform (I will have more than 1 listbox in this form )</p>
  
  <pre><code>public ActionResult GetStuff()
      {
  
         var Types = from m in db.ABCs
                     select m.Type.Distinct();
  
          return View(Types); 
      }
  </code></pre>
  
  <p>And then on my view i am required to have 
  @model IEnumerable so i can show on that page everything that the table abc has.</p>
  
  <p>So, can I create a viewModel that fills the lsitbox (I will need to fill at least 6 with the parameters that abc has so the user can search for abcs with those values, but i suppose that if i can understand how to do 1 i can do it for 6) with what I want and that allows me to show the entries that abc has? </p>
  
  <p>and this is the view ( i know a lot of things are wrong with it but its just to give an example)</p>
  
  <pre><code>@using (Html.BeginForm("getSelectedValues", "ABC", FormMethod.Get))
  {
      Type:@Html.DropDownList() 
  
      a:@Html.DropDownList()
  
      b:@Html.DropDownList()
  
      //and so on
  
      &lt;input type="submit" value="Filter" /&gt;
  }
  </code></pre>
  
  <p>Pardon for my ignorance for any aspect i missed but i am new to asp net mvc 5, also if anyone could just guide me or send me a guide on what I have to do i would greatly appreciate it. </p>