title: ASP.NET Core Razor Pages: Select multiple items from IEnumerable Dropdownlist
body: <p>I have a dropdownlist that I've been using in a project that allows me to click a button on one of the objects in the list. The button then routes me to a new page given an ID from the object I select. I'm curious to see if anyone might know a way to modify my existing code to allow me to select multiple objects from a dropdownlist. It wouldn't let me route to a new page, instead, I would be selecting multiple objects and returning a list of their ID's which I could then allow changes to be made to the objects correlating to these IDs on the same page. For example, there could be a list of locations. I would then want to be able to select a checkbox on a few of those locations and fill in a few text boxes to enter in information like a city or state. Once the information is entered, I could click a submit button and the page would refresh and show the updated data.</p>
  <p>Here is the code I have for the current dropdown list that I am using on a different page that allows me to select a single object and route to a new page with it. I am using ASP.NET Core 3.0 with Razor Pages.</p>
  <p>ViewAssessment.cshtml:</p>
  <pre><code>@page
  @model CustomerPageTest.Pages.View.ViewAssessmentModel
  @{
      ViewData[&quot;Title&quot;] = &quot;ViewAssessment&quot;;
  }
  
  &lt;link rel=&quot;stylesheet&quot; href=&quot;https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css&quot;&gt;
  
  &lt;div class=&quot;col-md-offset-4 justify-content-center&quot;&gt;
      &lt;h1 style=&quot;color:yellowgreen&quot;&gt;View Assessment&lt;/h1&gt;
  &lt;/div&gt;
  &lt;div&gt;
      &lt;p align=&quot;right&quot;&gt;
          &lt;a class=&quot;btn btn-dark&quot;
             asp-page=&quot;/Index&quot;&gt;Back&lt;/a&gt;
      &lt;/p&gt;
  &lt;/div&gt;
  &lt;form method=&quot;get&quot;&gt;
      &lt;div class=&quot;form-group&quot;&gt;
          &lt;div class=&quot;input-group&quot;&gt;
              &lt;input type=&quot;search&quot; placeholder=&quot;Search ID, Customer, Date Imported, vCenter, Imported By, or Notes&quot; class=&quot;form-control&quot; asp-for=&quot;SearchTerm&quot; /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/form&gt;
  
  &lt;table class=&quot;table&quot;&gt;
      &lt;tr class=&quot;text-light&quot; style=&quot;border-top: hidden !important&quot;&gt;
          &lt;td&gt;ID&lt;/td&gt;
          &lt;td&gt;Customer&lt;/td&gt;
          &lt;td&gt;Date Imported&lt;/td&gt;
          &lt;td&gt;vCenter&lt;/td&gt;
          &lt;td&gt;Imported By&lt;/td&gt;
          &lt;td&gt;Notes&lt;/td&gt;
      &lt;/tr&gt;
      @foreach (var assessment in Model.Assessments)
      {
      &lt;tr&gt;
          &lt;td class=&quot;text text-light&quot;&gt;@assessment.assessment_id&lt;/td&gt;
          &lt;td class=&quot;text text-light&quot;&gt;@assessment.CustomerName&lt;/td&gt;
          &lt;td class=&quot;text text-light&quot;&gt;@assessment.imported_data_datetime&lt;/td&gt;
          &lt;td class=&quot;text text-light&quot;&gt;@assessment.vcenter&lt;/td&gt;
          &lt;td class=&quot;text text-light&quot;&gt;@assessment.UserName&lt;/td&gt;
          &lt;td class=&quot;text text-light&quot;&gt;@assessment.notes&lt;/td&gt;
          &lt;td&gt;
              &lt;a class=&quot;btn btn-dark&quot;
                 asp-page=&quot;/View/EditAssessment&quot; asp-route-assessmentId=&quot;@assessment.assessment_id&quot;&gt;
                  &lt;i class=&quot;glyphicon glyphicon-pencil&quot;&gt;&lt;/i&gt;
              &lt;/a&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
      }
  &lt;/table&gt;
  </code></pre>
  <p>This is the front end of the dropdownlist page. It goes through a list of objects called Assessments and there is a search bar that allows me to search through any of the objects my Assessment class contains.</p>
  <p>ViewAssessment.cshtml.cs:</p>
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Threading.Tasks;
  using Microsoft.AspNetCore.Mvc;
  using Microsoft.AspNetCore.Mvc.RazorPages;
  using Microsoft.Extensions.Configuration;
  
  namespace CustomerPageTest.Pages.View
  {
      public class ViewAssessmentModel : PageModel
      {
          private readonly IAssessmentData assessmentData; //Allows access to Assessment interface
          private readonly IConfiguration config;
  
          [BindProperty(SupportsGet = true)]
          public string SearchTerm { get; set; } //Search term for search bar
  
          public IEnumerable&lt;CustomerPageTest.AssessmentView&gt; Assessments { get; set; } //Assessment that is used
  
          public ViewAssessmentModel(IConfiguration config, IAssessmentData assessmentData)
          {
              this.config = config;
              this.assessmentData = assessmentData;
          }
  
          public void OnGet()
          {
              Assessments = assessmentData.GetAssessmentsByName(SearchTerm);
  
              bool intOrString = false; //If false, its a string, if true, its an int
              try
              {
                  int convertToInt = Int32.Parse(SearchTerm);
                  intOrString = true;
              } catch (Exception) { }
  
              if (intOrString) //Whole if statement is for the search bar, enables searching data in any column
                  Assessments = assessmentData.SearchAssessmentById(SearchTerm);
              else
              {
                  if (!assessmentData.IsNullOrEmpty(assessmentData.GetAssessmentsByName(SearchTerm)))
                      Assessments = assessmentData.GetAssessmentsByName(SearchTerm);
                  else if (!assessmentData.IsNullOrEmpty(assessmentData.SearchAssessmentByDate(SearchTerm)))
                      Assessments = assessmentData.SearchAssessmentByDate(SearchTerm);
                  else if (!assessmentData.IsNullOrEmpty(assessmentData.SearchAssessmentByCenter(SearchTerm)))
                      Assessments = assessmentData.SearchAssessmentByCenter(SearchTerm);
                  else if (!assessmentData.IsNullOrEmpty(assessmentData.SearchAssessmentByUser(SearchTerm)))
                      Assessments = assessmentData.SearchAssessmentByUser(SearchTerm);
                  else if (!assessmentData.IsNullOrEmpty(assessmentData.SearchAssessmentByUser(SearchTerm)))
                      Assessments = assessmentData.SearchAssessmentByUser(SearchTerm);
              }
  
              
          }
      }
  }
  </code></pre>
  <p>This is the backend of my dropdownlist page. The main part of it is in the OnGet() method which calls a lot of functions for the search bar. You'll notice an interface called IAssessmentData. This is what grabs the list of Assessments to print out and contains the functions that make the search bar work.</p>
  <p>I hope I've explained the dropdownlist I currently have and how I want to modify it. Any ideas on how I could do this would be greatly appreciated!</p>