I work on razor asp.net core . I face issue i can't store selected value id and selected text of select option drop down on hidden fields
so I need to create two hidden fields first hidden field to store selected value id and second for store selected text
public class LabelPrintingModel : PageModel
{
[BindProperty]
public List PrinterList { get; set; }
public async void OnGet()
{
PrinterList = dtprinters.AsEnumerable()
.Select(row => new LabelPrinitingView
{
// Map the values from the DataRow to the properties of the PrintServer object
UserPC = (string)row["UserPC"],
PrinterName = row["PrinterName"].ToString()
// etc.
})
.ToList();
}
public class LabelPrinitingView
{
public string UserPC { get; set; }
public string PrinterName { get; set; }
}
Deepak RawatPosted Jul 10, 2023, 7:28 AM
To store the selected value and text of the dropdown in hidden fields, you can use JavaScript/jQuery. Here's an example of how you can achieve that:
Add a script section to your HTML page where you can handle the selection change event of the dropdown and update the hidden fields accordingly:
In your server-side code, you can access the values of the hidden fields by binding them to properties in your model:
when the user selects an option from the dropdown, the hidden fields will be updated with the selected value and text. When the form is submitted, the selected values will be available in the
SelectedPrinterIdandSelectedPrinterTextproperties of your model.Amit MohantyPosted Jul 10, 2023, 5:43 AM