title: .Net Core Razor page with multiple drop-down's for the same entity
body: <p>Is there any way I can have multiple drop-down menu displaying the data from the same database entity on the same razor page without creating several classes with new IDs (e.g. ResourceID; ResourceID1; ResourceID2)</p>
  
  <p>I am able to display the drop down with the appropriate data from the MS SQL database in the 'Create.cshtml' and 'Edit.cshtml' razor pages, but the chosen data when saved displays the ID of the chosen resource instead of the name of the resource in the 'Index.cshtml', 'Detail.cshtml' and 'Delete.cshtml' views.</p>
  
  <p>The Resource model:</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace ProjectReporting.Models
  {
      public class Resource
      {
          public int ID { get; set; }
  
          [Display(Name = "First Name")]
          public string FirstName { get; set; }
  
          [Display(Name = "Last Name")]
          public string LastName { get; set; }
  
          [Display(Name = "Long Name")]
          public string LongName { get; set; }
  
          [DefaultValue(true)]
          [Display(Name = "Active")]
          public bool IsActive { get; set; } = true;
  
          [Display(Name = "Is Manager")]
          public bool IsManager { get; set; }
  
          [Display(Name = "Is Forecast Owner")]
          public bool IsForecastOwner { get; set; }
  
          public ICollection&lt;Project&gt; Projects { get; set; }
  
      }
  }
  </code></pre>
  
  <p>The Project model:</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace ProjectReporting.Models
  {
      public class Project
      {
          public int ID { get; set; }
  
          [Display(Name = "ID")]
          public int PID { get; set; }
  
          [Display(Name = "Project Name")]
          public string ProjectName { get; set; }
  
          [Display(Name = "Forecast Owner")]
          public int ResourceID { get; set; }
          public Resource Resource { get; set; }
  
          [Display(Name = "DSM")]
          public int? ResourceID1 { get; set; }
  
          public ICollection&lt;ProjectComment&gt; ProjectComments { get; set; }
  
      }
  }
  </code></pre>
  
  <p>The Create.cshtml page:</p>
  
  <pre class="lang-html prettyprint-override"><code>@page
  @model ProjectReporting.Pages.Projects.CreateModel
  
  @{
      ViewData["Title"] = "Create";
  }
  
  &lt;h1&gt;Create&lt;/h1&gt;
  
  &lt;h4&gt;Project&lt;/h4&gt;
  &lt;hr /&gt;
  &lt;div class="row"&gt;
      &lt;div class="col-md-4"&gt;
          &lt;form method="post"&gt;
              &lt;div asp-validation-summary="ModelOnly" class="text-danger"&gt;&lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Project.PID" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="Project.PID" class="form-control" /&gt;
                  &lt;span asp-validation-for="Project.PID" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Project.ProjectName" class="control-label"&gt;&lt;/label&gt;
                  &lt;input asp-for="Project.ProjectName" class="form-control" /&gt;
                  &lt;span asp-validation-for="Project.ProjectName" class="text-danger"&gt;&lt;/span&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Project.ResourceID" class="control-label"&gt;&lt;/label&gt;
                  &lt;select asp-for="Project.ResourceID" class="form-control" asp-items="ViewBag.ResourceID"&gt;&lt;option value="" default="" selected=""&gt;-- Select --&lt;/option&gt;&lt;/select&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;label asp-for="Project.ResourceID1" class="control-label"&gt;&lt;/label&gt;
                  &lt;select asp-for="Project.ResourceID1" class="form-control" asp-items="ViewBag.ResourceID1"&gt;&lt;option value="" default="" selected=""&gt;-- Select --&lt;/option&gt;&lt;/select&gt;
              &lt;/div&gt;
              &lt;div class="form-group form-check"&gt;
                  &lt;label class="form-check-label"&gt;
                      &lt;input class="form-check-input" asp-for="Project.IsArchived" /&gt; @Html.DisplayNameFor(model =&gt; model.Project.IsArchived)
                  &lt;/label&gt;
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;input type="submit" value="Create" class="btn btn-primary" /&gt;
              &lt;/div&gt;
          &lt;/form&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div&gt;
      &lt;a asp-page="Index"&gt;Back to List&lt;/a&gt;
  &lt;/div&gt;
  
  @section Scripts {
      @{await Html.RenderPartialAsync("_ValidationScriptsPartial");}
  }
  
  </code></pre>
  
  <p>The Create.cshtml page:</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace ProjectReporting.Pages.Projects
  {
      public class CreateModel : PageModel
      {
          private readonly ProjectReporting.Data.ApplicationDbContext _context;
  
          public CreateModel(ProjectReporting.Data.ApplicationDbContext context)
          {
              _context = context;
          }
  
          public IActionResult OnGet()
          {
              ViewData["OrganisationID"] = new             SelectList(_context.ProjectType.Where(a =&gt; a.IsActive == true), "ID", "TypeName");
              ViewData["ResourceID"] = new SelectList(_context.Resource.Where(a =&gt; a.IsActive &amp; a.IsForecastOwner == true), "ID", "LongName");
              ViewData["ResourceID1"] = new SelectList(_context.Resource.Where(a =&gt; a.IsActive == true), "ID", "LongName");
              return Page();
          }
  
          [BindProperty]
          public Project Project { get; set; }
  
          // To protect from overposting attacks, please enable the specific properties you want to bind to, for
          // more details see https://aka.ms/RazorPagesCRUD.
          public async Task&lt;IActionResult&gt; OnPostAsync()
          {
              if (!ModelState.IsValid)
              {
                  return Page();
              }
  
              _context.Project.Add(Project);
              await _context.SaveChangesAsync();
  
              return RedirectToPage("./Index");
          }
      }
  }
  
  </code></pre>
  
  <p>The Index.cshtml page:</p>
  
  <pre class="lang-html prettyprint-override"><code>@page
  @model ProjectReporting.Pages.Projects.IndexModel
  
  @{
      ViewData["Title"] = "Index";
  }
  
  &lt;h1&gt;Index&lt;/h1&gt;
  
  &lt;p&gt;
      &lt;a asp-page="Create"&gt;Create New&lt;/a&gt;
  &lt;/p&gt;
  &lt;table class="table"&gt;
      &lt;thead&gt;
          &lt;tr&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Project[0].PID)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Project[0].Organisation)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Project[0].ProjectName)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Project[0].Resource)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Project[0].ResourceID1)
              &lt;/th&gt;
              &lt;th&gt;
                  @Html.DisplayNameFor(model =&gt; model.Project[0].IsArchived)
              &lt;/th&gt;
              &lt;th&gt;&lt;/th&gt;
          &lt;/tr&gt;
      &lt;/thead&gt;
      &lt;tbody&gt;
  @foreach (var item in Model.Project) {
          &lt;tr&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.PID)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Organisation.OrgName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.ProjectName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.Resource.LongName)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; c)
              &lt;/td&gt;
              &lt;td&gt;
                  @Html.DisplayFor(modelItem =&gt; item.IsArchived)
              &lt;/td&gt;
              &lt;td&gt;
                  &lt;a asp-page="./Edit" asp-route-id="@item.ID"&gt;Edit&lt;/a&gt; |
                  &lt;a asp-page="./Details" asp-route-id="@item.ID"&gt;Details&lt;/a&gt; |
                  &lt;a asp-page="./Delete" asp-route-id="@item.ID"&gt;Delete&lt;/a&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
  }
      &lt;/tbody&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>The item.Resource.LongName works fine for the first resource, but I would like the same to happen with the item.Resource.LongName.</p>
  
  <p>The Index.cshtml.cs</p>
  
  <pre class="lang-cs prettyprint-override"><code>namespace ProjectReporting.Pages.Projects
  {
      public class IndexModel : PageModel
      {
          private readonly ProjectReporting.Data.ApplicationDbContext _context;
  
          public IndexModel(ProjectReporting.Data.ApplicationDbContext context)
          {
              _context = context;
          }
  
          public IList&lt;Project&gt; Project { get;set; }
  
          public async Task OnGetAsync()
          {
              Project = await _context.Project
                  .Include(p =&gt; p.Resource).ToListAsync();
          }
      }
  }
  </code></pre>
  
  <p>I have set the FK in the migration file to create the DB to be able to retrieve the data and would like to avoid having to create one class file by resource. </p>
  
  <pre class="lang-cs prettyprint-override"><code>table.ForeignKey(
       name: "FK_Project_Resource_ResourceID",
       column: x =&gt; x.ResourceID,
       principalTable: "Resource",
       principalColumn: "ID",
       onDelete: ReferentialAction.Restrict);
  table.ForeignKey(
       name: "FK_Project_Resource_ResourceID1",
       column: x =&gt; x.ResourceID1,
       principalTable: "Resource",
       principalColumn: "ID",
       onDelete: ReferentialAction.Restrict);
  </code></pre>
  
  <p>The result shows the right data in the drop-down and the correct Resource ID selected when saved. However, the index, details and delete page only display the ResourceID instead of the LongName. If I use Resource.LongName for the second ResourceID1, it rightly displays the same LongName than for ResourceID.</p>
  
  <p>How can I have multiple resource drop-down on the page that point to the same entity and display the LongName on the Index, Detail and Delete pages?</p>