英文:
How to get selected text printer Name from selected option drop down on post method?
问题
在页面模型的OnPostPrintAdc
方法中,您可以通过Request.Form
来获取选择的打印机名称的文本。以下是如何在该方法中获取所选打印机名称的文本:
public void OnPostPrintAdc()
{
string selectedPrinterName = Request.Form["selectprinterid"];
// 现在,selectedPrinterName 包含了所选打印机的名称文本
// 您可以在这里执行您希望的操作
}
这样,您就可以在OnPostPrintAdc
方法中获取所选打印机名称的文本。不需要使用数据库来获取它,只需从表单中获取它即可。
英文:
I work on asp.net razor page .I face Issue I can't get selected text from selected options drop down on page model on post method
on page html
<form id="FrmShelfLabelPrintrSetup" method="post" asp-page-handler="PrintAdc" >
<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>
<button id="PrintAdc" type="submit" name="PrintAdcButton" value="PrintAdc" style="width:100px;margin-top:7px;" class="btn btn-primary">Search</button>
</form>
Now How to get printer name selected text on post method on Page Model
public class LabelPrintingModel : PageModel
{
public LabelPrintingModel()
{
}
public void OnPostPrintAdc()
{
//How to get printer name selected text here
}
}
Updated post
so are there are any solution for pass selected text printer name direct from html to page model without using database to fetch it or use printer name as value and text
答案1
得分: 1
以下是您要翻译的内容:
Option 1:
将选项值更改为:value="@printer.PrinterName"
<option value="@printer.PrinterName">@printer.PrinterName</option>
结果:
Option 2:
var name = from s in PrinterList
where s.UserPC == selectprinterid
select s.PrinterName;
更新:
public class LabelPrintingModel : PageModel
{
public List<xxxxxxx> PrinterList{ get; set; }
public LabelPrintingModel()
{
PrinterList = //获取您的数据
}
public void OnPostPrintAdc()
{
//在这里获取所选文本的打印机名称
var name = from s in PrinterList
where s.UserPC == selectprinterid
select s.PrinterName;
}
}
英文:
> How to get printer name selected text on post method on Page Model
There are two ways:
Option 1:
Change the option value into : value="@printer.PrinterName"
<option value="@printer.PrinterName">@printer.PrinterName</option>
result:
Option 2:
var name = from s in PrinterList
where s.UserPC == selectprinterid
select s.PrinterName;
Update:
public class LabelPrintingModel : PageModel
{
public List<xxxxxxx> PrinterList{ get; set; }
public LabelPrintingModel()
{
PrinterList= //get your data
}
public void OnPostPrintAdc()
{
//How to get printer name selected text here
var name = from s in PrinterList
where s.UserPC == selectprinterid
select s.PrinterName;
}
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论