title: asp.net core mvc SelectList for filter
body: <p>I am working on an asp.net MVC Core 2.0 application.</p>
  
  <p>I have a page which contains a list of items.</p>
  
  <p>I want to put several Dropdown list at the top of this page. This Dropdowns are filters.</p>
  
  <p>Here is an example:</p>
  
  <p>Here is my cshtml view:</p>
  
  <pre><code>@model List&lt;Person&gt;
  
  Genre : &lt;select asp-items="ViewBag.genres"&gt;&lt;/select&gt;
  
  &lt;table border="1"&gt;
  @foreach (var item in Model)
  {
       &lt;tr&gt;
              &lt;td&gt;@item.name&lt;/td&gt;
              &lt;td&gt;@item.genre&lt;/td&gt;
              ...
        &lt;/tr&gt;
  }
  </code></pre>
  
  <p>Here is the associated controller action method:</p>
  
  <pre><code>        public async Task&lt;IActionResult&gt; Index(String selected_genre)
          {
              ViewBag.genres = new SelectList(new [] 
                  {
                      new { id = "", name = "All" },
                      new { id = "1", name = "Male" },
                      new { id = "2", name = "Female" },
                      new { id = "3", name = "Don't know" },
                  }, 
                  "id", "name", selected_genre);
              ...
  </code></pre>
  
  <p>What i want to do is to reload the page when the users select something in the genre dropdown.</p>
  
  <p>If the user selects "Female", i want the page to be reloaded:</p>
  
  <p><a href="http://myapplication/MyController/Index?selected_genre=2&amp;param2=3" rel="nofollow noreferrer">http://myapplication/MyController/Index?selected_genre=2&amp;param2=3</a></p>
  
  <p>Please note there might be other filters (this is why i put param2=3 in my example).</p>
  
  <p>I have managed to make it work with javascript (onchange event). It works but it is very ugly.</p>
  
  <p>I want to know if there is a way to do this with ASP.Net core 2 functionalities</p>
  
  <p>Thanks</p>