简体   繁体   English

如何将我的 @onchange 事件绑定到 Id 字段而不是硬编码到一个?

[英]How can I bind my @onchange event to an Id field rather than hardcoding to one?

I'm currently creating a page which displays information based on what's selected from the drop-down.我目前正在创建一个页面,该页面根据从下拉列表中选择的内容显示信息。

My current select list looks like this我当前的 select 列表看起来像这样

<Select id="Person" class="form-select" bind-value="@VisitDTO.Id" style="width: 500px" @onchange="() => @VisitSelected(5)">
                <option value="0">Ivco Ref:</option>
                @foreach (var visits in Visits)
                {
                    <option value="@visits.Id">@visits.Id</option>
                }
            </Select>

As you can see, I've hardcoded the parameter to visitid: 5 - What could I put in the @VisitSelected method (or anywhere else) to bind that to the actual visitid field?如您所见,我已将参数硬编码为 visitid: 5 - 我可以在 @VisitSelected 方法(或其他任何地方)中放入什么来将其绑定到实际的 visitid 字段?

@onchange EventCallback passes a ChangeEventArgs parameter to your event handler which you can use to determine the selected value. @onchange EventCallbackChangeEventArgs参数传递给您的事件处理程序,您可以使用它来确定选定的值。

<select id="Person" class="form-select" value="@VisitDTO.Id" style="width: 500px" @onchange="VisitSelected">
    <option value="0">Ivco Ref:</option>
    @foreach (var visits in Visits)
    {
        <option value="@visits.Id">@visits.Id</option>
    }
</select>

@code {
    void VisitSelected(ChangeEventArgs e)
    {
         var selectedValue = e?.Value?.ToString();

         // do other stuff
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何强制浏览器在现有标签页而不是新标签页中打开我的网址? - How can I force the browser to open my urls in an existing tab rather than a new one? 如何通过进程 ID 而不是窗口句柄向特定进程发送消息? - How can I send a message to a specific process by process id rather than by window handle? 使用 CsvHelper 库,我怎样才能将空字段读取为 null 而不是空字符串? - Using the CsvHelper library, how can I read an empty field as null rather than an empty string? 如何设置带有“日期”字段的Razor“ EditorFor”的“ onchange”事件? - How do I set an “onchange” event of a Razor “EditorFor” with a Date field? 如何将DataGridViewComboBoxColumn绑定到OnChange事件(C#) - How to bind DataGridViewComboBoxColumn to a OnChange event (C#) 如何获取保存的html文件而不显示原始html? - How can I get my saved html file to be rendered rather than displaying the raw html? 如何制作使用 oninput 而不是 onchange 绑定的 EditForm Input? - How to make an EditForm Input that binds using oninput rather than onchange? 如何将命令绑定到本地事件? - How can I bind a command to a local event? 如何将字段绑定到用户控件 - How can I bind a field to a user control 如何返回流而不是写入磁盘? - How can I return a stream rather than writing to disk?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM