[英]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
EventCallback
将ChangeEventArgs
参数传递给您的事件处理程序,您可以使用它来确定选定的值。
<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.