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.
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.
ViewAssessment.cshtml:
@page
@model CustomerPageTest.Pages.View.ViewAssessmentModel
@{
ViewData["Title"] = "ViewAssessment";
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">
<div class="col-md-offset-4 justify-content-center">
<h1 style="color:yellowgreen">View Assessment</h1>
</div>
<div>
<p align="right">
<a class="btn btn-dark"
asp-page="/Index">Back</a>
</p>
</div>
<form method="get">
<div class="form-group">
<div class="input-group">
<input type="search" placeholder="Search ID, Customer, Date Imported, vCenter, Imported By, or Notes" class="form-control" asp-for="SearchTerm" />
</div>
</div>
</form>
<table class="table">
<tr class="text-light" style="border-top: hidden !important">
<td>ID</td>
<td>Customer</td>
<td>Date Imported</td>
<td>vCenter</td>
<td>Imported By</td>
<td>Notes</td>
</tr>
@foreach (var assessment in Model.Assessments)
{
<tr>
<td class="text text-light">@assessment.assessment_id</td>
<td class="text text-light">@assessment.CustomerName</td>
<td class="text text-light">@assessment.imported_data_datetime</td>
<td class="text text-light">@assessment.vcenter</td>
<td class="text text-light">@assessment.UserName</td>
<td class="text text-light">@assessment.notes</td>
<td>
<a class="btn btn-dark"
asp-page="/View/EditAssessment" asp-route-assessmentId="@assessment.assessment_id">
<i class="glyphicon glyphicon-pencil"></i>
</a>
</td>
</tr>
}
</table>
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.
ViewAssessment.cshtml.cs:
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<CustomerPageTest.AssessmentView> 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);
}
}
}
}
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.
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!


dropdownlistyou mentioned,is it meanstablein your cshtml? Do you mean you want to have a checkbox before each piece of data inforeach?And the selected data can change to input,and then you can edit the data and click the button after the piece of data to submit it.