title: Populate razor select list from database
body: <p>I have looked through numerous examples online of populating a select list or even a html drop down list but nothing seems to be working.</p>
  
  <p>code in my cshtml.cs class</p>
  
  <pre class="lang-cs prettyprint-override"><code>        public DutyWeb_DEVContext db;
          public AddApplicationModel(DutyWeb_DEVContext db) =&gt; this.db = db;
          public List&lt;SelectListItem&gt; ministryItems {get;set;}
  
          public void OnGet()
          {
              ministryItems = db.Ministry.Select(x=&gt;new SelectListItem{Value=x.Name,Text=x.Name}).ToList();
              Console.WriteLine("------------"+ministryItems.Count);
          }
  </code></pre>
  
  <p>code in the cshtml class </p>
  
  <pre><code>            &lt;input type="text" name="appName" placeholder="Enter Application Name"&gt;
              &lt;select asp-items="Model.ministryItems"&gt;
                  &lt;option&gt;Select Ministry&lt;/option&gt;
              &lt;/select&gt;
  </code></pre>
  
  <p>I keep getting the error </p>
  
  <blockquote>
    <p>Pages\AddApplication.cshtml(14,63): error CS0266: Cannot implicitly convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.IEnumerable'. An explicit conversion exists (are you missing a cast?)</p>
  </blockquote>
  
  <p>Ministry Class </p>
  
  <pre><code>public partial class Ministry
  {
      public Ministry()
      {
          Application = new HashSet&lt;Application&gt;();
      }
  
      public int MinistryId { get; set; }
      public string Name { get; set; }
      public string ShortName { get; set; }
      public int? Corguid { get; set; }
  
      public ICollection&lt;Application&gt; Application { get; set; }
  }
  </code></pre>