title: How to get data from database in listbox using List<> in as.net MVC
body: <p>I am new in MVC, I have search on many site for fetching data from database and display in Listbox but I did’nt get any proper answer, in Every site there is hardcoded example for listbox just like this.</p>
  
  <pre><code>public List&lt;Product&gt; allProducts = new List&lt;Product&gt;
  {
  new Product(1, "Games Console", "Fun for all the family", 199.99m),
  new Product(2, "MP3 player", "Listen to your favourite tunes on the move", 99.99m),
  new Product(3, "Smart Phone", "Apps, apps, apps", 399.99m),
  new Product(4, "Digital Photo frame", "All your photos in one beautiful frame", 49.99m),
  new Product(5, "E-book reader", "Take your favourite books on the move with you", 149.99m),
  new Product(6, "DVD Box Set", "All of season one plus exclusive extras", 39.99m)
  };
  </code></pre>
  
  <p>But I want to display data from database just like this;</p>
  
  <pre><code>public List&lt;Model&gt; allModels = new List&lt;Model&gt;
  {
  //Query to fetch data from database
  };
  </code></pre>
  
  <p>I am not getting how to write the query in List, Please tell me how to write query inside the above syntax……</p>
  
  <p>Please help me….</p>
  
  <p><strong>UPDATED</strong></p>
  
  <p>Actually I wanted to display the two list box one that contain the data from db and 2ndlistbox contains the selected item from 1stlistbox,
  My code is like this…</p>
  
  <p>Model:</p>
  
  <pre><code>public class Model
      {
  public int Id { get; set; }
  public string Name { get; set; }
  public string Class { get; set; }
      }
  </code></pre>
  
  <p>In that I have added some data in database </p>
  
  <p>ViewModels Class:</p>
  
  <pre><code>public class ViewModel
      {
  public List&lt;Model&gt; AvailableModel { get; set; }
  public List&lt;Model&gt; RequestedModel { get; set; }
  
  public int[] AvailableSelected { get; set; }
  public int[] RequestedSelected { get; set; }
  
  public string SavedRequested { get; set; }
      }
  </code></pre>
  
  <p>I am Following this Articals:
  [<a href="http://www.codeproject.com/Articles/136730/ASP-NET-MVC-Basics-Working-with-ListBoxes%5d%5b1%5d" rel="nofollow">http://www.codeproject.com/Articles/136730/ASP-NET-MVC-Basics-Working-with-ListBoxes][1]</a></p>
  
  <p>As your suggested code:</p>
  
  <pre><code>var data = (from m indb.Models
  selectm.Name);
  
  List&lt;Model&gt;modellist = data.ToList();
  </code></pre>
  
  <p>I have write this and 
  it throws An error:</p>
  
  <pre><code>Cannot implicitly convert type 'System.Collections.Generic.List&lt;string&gt;' to 'System.Collections.Generic.List&lt;DemoListBox.Models.Model&gt;'
  </code></pre>