title: Cannot get selected value from SelectList Razor Pages
body: <p>I'm making a simple MovieApp using <code>Razor Pages</code>. I have two models: <strong>Movie</strong> <code>* - 1</code> <strong>Genre</strong>. What I want is that when I navigate to <strong>Genres</strong> page and select a particular Genre, I want to show <strong>List</strong> of all the movies associated with this Genre, and I would like to be able to select and <strong>Navigate</strong> to the <strong>Movie</strong> from <strong>Genre</strong>.</p>
  <p>The problem that I have is that the Razor Pages' <strong>SelectList</strong> is not Binding selected <em>reference</em> value (i.e objects of Movies) from the list, but when I have <code>IDs</code> of <strong>Movies</strong> instead, I'm getting the selected value correctly.</p>
  <p>Here is my code:</p>
  <p><strong>Details.cshtml</strong></p>
  <pre><code>&lt;div&gt;
  &lt;h4&gt;Genre&lt;/h4&gt;
  &lt;hr /&gt;
  &lt;form method=&quot;post&quot;&gt;
      &lt;dl class=&quot;row&quot;&gt;
          &lt;dt class=&quot;col-sm-2&quot;&gt;
              @Html.DisplayNameFor(model =&gt; model.Genre.GenreTitle)
          &lt;/dt&gt;
          &lt;dd class=&quot;col-sm-10&quot;&gt;
              @Html.DisplayFor(model =&gt; model.Genre.GenreTitle)
          &lt;/dd&gt;
      &lt;/dl&gt;
      &lt;div class=&quot;form-group&quot; style=&quot;width: 250px;&quot;&gt;
          &lt;label asp-for=&quot;MoviesSL&quot; class=&quot;control-label&quot;&gt;&lt;/label&gt;
          &lt;select asp-for=&quot;SelectedMovie&quot; class=&quot;form-control&quot;
                  asp-items=&quot;Model.MoviesSL&quot;&gt;
          &lt;/select&gt;
      &lt;/div&gt;
      &lt;span asp-validation-for=&quot;SelectedMovie.ID&quot; class=&quot;text-danger&quot;&gt;&lt;/span&gt;
      &lt;div&gt;
          &lt;input type=&quot;submit&quot; value=&quot;Navigate&quot; class=&quot;btn btn-info&quot; /&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><strong>Details.cshtml.cs</strong></p>
  <pre><code>    public Genre Genre { get; set; }
      [Display(Name = &quot;Movies list&quot;)]
      public SelectList MoviesSL { get; set; }
      private Movie selectedMovie;
      [BindProperty]
      public Movie SelectedMovie 
      {
          get =&gt; selectedMovie;
          set
          {
              selectedMovie = value;
              //int g = 0;
          }
      }
  
      public async Task&lt;IActionResult&gt; OnGetAsync(int? id)
      {
          if (id == null)
          {
              return NotFound();
          }
  
          Genre = await _context.Genre.Include(m =&gt; m.Movies).FirstOrDefaultAsync(m =&gt; m.GenreId == id);
          MoviesSL = new SelectList(Genre.Movies);
  
          //int g = 0;
  
          if (Genre == null)
          {
              return NotFound();
          }
          return Page();
      }
  
      public void OnPost()
      {
          var k = SelectedMovie;
  
          //int g = 0;
      }
  </code></pre>
  <p><strong>Movie.cs</strong></p>
  <pre><code>public class Movie
      {
          [Key]
          public int ID { get; set; }
  
          [Required]
          [StringLength(60, MinimumLength = 3)]
          public string Title { get; set; }
  
          [DataType(DataType.Date)]
          [Display(Name = &quot;Release Date&quot;)]
          [DisplayFormat(DataFormatString = &quot;{0:dd-MM-yyyy}&quot;, ApplyFormatInEditMode = true)]
          public DateTime ReleaseDate { get; set; }
  
          [Range(1, 300)]
          [DataType(DataType.Currency)]
          [Column(TypeName = &quot;decimal(18,2)&quot;)]
          public decimal Price { get; set; }
  
          [Required]
          [StringLength(5)]
          [RegularExpression(@&quot;^[A-Z]+[a-zA-Z0-9&quot;&quot;'\s-]*$&quot;)]
          public string Rating { get; set; }
  
          public int GenreId { get; set; }
          public Genre Genre { get; set; }
  
          public override string ToString()
          {
              return Title;
          }
      }
  </code></pre>
  <p><strong>Genre.cs</strong></p>
  <pre><code>public class Genre
  {
      public Genre()
      {
          Movies = new List&lt;Movie&gt;();
      }
  
      [Key]
      public int GenreId { get; set; }
      [Required]
      [StringLength(30, MinimumLength = 5)]
      [Display(Name = &quot;Genre Title&quot;)]
      [RegularExpression(@&quot;^[A-Z]+[a-zA-Z]*$&quot;)]
      public string GenreTitle { get; set; }
  
      [Display(Name = &quot;Number of movies&quot;)]
      public ICollection&lt;Movie&gt; Movies { get; set; }
  
      public override string ToString()
      {
          return GenreTitle;
      }
  }
  </code></pre>
  <p>When I select a movie from the list and try to <em>&quot;navigate&quot;</em> through the post method I get an empty <strong>Movie</strong> object.</p>
  <p><a href="https://i.stack.imgur.com/LjHX3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LjHX3.png" alt="When I select a movie from the list, I get an empty Movie object" /></a></p>
  <p>However, when I have <strong>SelectList</strong> of <code>IDs</code> instead <code>Movies</code>, it works properly:</p>
  <p><a href="https://i.stack.imgur.com/e0fHH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/e0fHH.png" alt="Working correctly" /></a></p>