title: MVC populating drop down list from database
body: <p>Im pretty new to MVC. Im trying to populate a drop downlist with currencies retrieved from database. What am I doing wrong?</p>
  
  <pre><code>@model IEnumerable&lt;DSABankSolution.Models.ExchangeRates&gt;
  
  @{
      ViewBag.Title = "Exchange Rates";
      Layout = "~/Views/Shared/_Layout.cshtml";
  }
  
  &lt;br /&gt; &lt;br /&gt; 
  
  
       &lt;input type="text" size="5" value="1" /&gt;
          @Html.DropDownList("currency", Model.Select(p =&gt; new SelectListItem{ Text = p.Name, Value = p.ID})) 
          to  
         @Html.DropDownList("currency", Model.Select(p =&gt; new SelectListItem { Text = p.Name, Value = p.ID }));
      &lt;br /&gt; &lt;br /&gt; &lt;input type="submit" name="Convert" /&gt;
  </code></pre>
  
  <p>ExchangeRate Model:</p>
  
  <pre><code>public class ExchangeRates
  {
      public string ID { get; set; }
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>ExchangeRate Controller:</p>
  
  <pre><code> public ActionResult Index()
      {
          IEnumerable&lt;CommonLayer.Currency&gt; currency = CurrencyRepository.Instance.getAllCurrencies().ToList();
          //ViewBag.CurrencyID = new SelectList(currency, "ID");
          //ViewBag.Currency = new SelectList(currency, "Name");
  
          return View(currency);
      }
  </code></pre>
  
  <p>Currency Repository:</p>
  
  <pre><code>public List&lt;CommonLayer.Currency&gt; getAllCurrencies()
      {
          var query = from curr
                      in this.Entity.Currencies
                      select curr;
  
          return query.ToList();
      }
  </code></pre>
  
  <p>Error I am getting:</p>
  
  <blockquote>
    <p>The model item passed into the dictionary is of type
    'System.Collections.Generic.List<code>1[CommonLayer.Currency]', but this
    dictionary requires a model item of type
    'System.Collections.Generic.IEnumerable</code>1[DSABankSolution.Models.ExchangeRates]'.</p>
  </blockquote>
  
  <p>Thanks!</p>