如何从选定的选项下拉列表中使用POST方法获取所选文本打印机名称?

huangapple go评论64阅读模式
英文:

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=&quot;@printer.PrinterName&quot;>@printer.PrinterName</option>

结果:

如何从选定的选项下拉列表中使用POST方法获取所选文本打印机名称?

Option 2:

var name = from s in PrinterList
           where s.UserPC == selectprinterid
           select s.PrinterName;

更新:

public class LabelPrintingModel : PageModel
{ 
    public List&lt;xxxxxxx&gt; 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=&quot;@printer.PrinterName&quot;

 &lt;option value=&quot;@printer.PrinterName&quot;&gt;@printer.PrinterName&lt;/option&gt;

result:

如何从选定的选项下拉列表中使用POST方法获取所选文本打印机名称?

Option 2:

 var name = from s in PrinterList
                       where s.UserPC == selectprinterid
                       select s.PrinterName;

Update:

public class LabelPrintingModel : PageModel
 { 
public List&lt;xxxxxxx&gt; 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;
 }
}

huangapple
  • 本文由 发表于 2023年6月26日 17:36:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76555422.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定