title: How Do I Add a DropDownList In My View From my Local Database in ASP .NET MVC?
body: <p>I'm trying to create a DropDownList for my View in my MVC Web Application from my Local Database in which I've stored <em><strong>Games with an Id, a GameName, GameDescription, GameImage, Genre and a ReleaseYear.</strong></em></p>
  <p>The only value I want in my DropDownList is the <strong>GameName</strong> data from my Database.</p>
  <p>I'm using another model called Highscores.cs in my View but I want to use the Games.cs model here together with the Highscores model and create the DropDownList from the Games.cs model with the GameName value. I've tried to search for the solution but nothing works which of which I've tried.</p>
  <p>Here is my Games.cs model:</p>
  <pre><code>public class Games
      {
          public int Id { get; set; }
          public string GameName { get; set; }
          public string GameDescription { get; set; }
          public string GameImage { get; set; }
          public string Genre { get; set; }
          public DateTime ReleaseYear {get; set;}
      }
  </code></pre>
  <p>Here is the View I want to create my DropDownList in:</p>
  <pre><code>@model Inlämningsuppgift_Nummer_2.Models.Highscores
  
  &lt;h1&gt;New&lt;/h1&gt;
  
  &lt;h4&gt;Register New Highscore&lt;/h4&gt;
  &lt;hr /&gt;
  &lt;div class=&quot;row&quot;&gt;
      &lt;div class=&quot;col-md-4&quot;&gt;
          &lt;form asp-action=&quot;New&quot;&gt;
              &lt;div asp-validation-summary=&quot;ModelOnly&quot; class=&quot;text-danger&quot;&gt;&lt;/div&gt;
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;label asp-for=&quot;Game&quot; class=&quot;control-label&quot;&gt;&lt;/label&gt;
                  @* I want my DropDownList here from my model Games with the value of GameName *@
  
                  @*@Html.DropDownListFor(model =&gt; model.Highscores.Game, new SelectList(Model.Games.GameName, &quot;Select Game&quot;))*@
  
                  &lt;span asp-validation-for=&quot;Game&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
              &lt;/div&gt;
  </code></pre>
  <p>Here is my controller:</p>
  <pre><code>public IActionResult New()
          {
              CommonViewModel commonViewModel = new CommonViewModel();
  
              var gamesList = commonViewModel.Games.GameName.ToList();
  
              return View(gamesList);
          }
  </code></pre>
  <p>And here is my CommonViewModel:</p>
  <pre><code>public class CommonViewModel
      {
          public Highscores Highscores { get; set; }
          public Games Games { get; set; }
      }
  </code></pre>