I work on razor asp.net core 6 . 我面临问题,我可以储存某些价值,某些选择案文在隐蔽的田地上消失。
因此,我需要创建两个隐藏的领域。
储存某些价值的首个隐蔽领域
第二版
我曾尝试过:
<div class="col-md-3 col-lg-2">
<label for="printerserver-selectlbl" style="margin-left:3px;font-size:15px;font-family: Open Sans , sans-serif;font-weight: bold;">Print Location</label>
<select id="PrinterName-select" asp-for="SelectedPrinterId" name="selectprinterid" class="form-select" style="margin-left:3px;font-size:15px;font-family: Open Sans , sans-serif;font-weight: bold;">
<option value="0">--Select--</option>
@foreach (var printer in Model.PrinterList)
{
<option value="@printer.UserPC">@printer.PrinterName</option>
}
</select>
</div>
public class LabelPrintingModel : PageModel
{
[BindProperty]
public List<LabelPrinitingView> 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; }
}
我试图做些什么
var selectElement = document.getElementById("PrinterName-select");
selectElement.addEventListener("change", function () {
var selectedOption = selectElement.options[selectElement.selectedIndex];
var selectedText = selectedOption.text;
var selectedId = selectedOption.id;
console.log("Selected Text: " + selectedText);
console.log("Selected ID: " + selectedId);
<input type="hidden" id="selected-option-text" name="selected-option-text" value="@Model.SelectedOptionText" />
<input type="hidden" id="selected-option-value" name="selected-option-value" value="@Model.选用 价值" />
但是,仍然有两种特性在页面模型中无效。
选用 价值
SelectedOptionText
因此,如果是解决问题,请