Blazor:如何在< select>中使用onchange事件.还使用@bind时? [英] Blazor: How to use the onchange event in <select> when using @bind also?

查看:374
本文介绍了Blazor:如何在< select>中使用onchange事件.还使用@bind时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<select>中进行选择后,我需要能够运行一个函数.问题是我也与@bind绑定在一起,当我尝试使用@onchange时,我收到一条错误消息,指出它已经被@bind使用.我尝试使用@onselectionchange,但这不执行任何操作(不运行该功能).我可能会忘记@bind,而只是将@onchange分配给一个函数,但是我不确定如何将所选值传递给该函数.

I need to be able to run a function after a selection in made in a <select>. The issue is I'm also binding with @bind and I get a error when I try to use @onchange stating that it is already in use by the @bind. I tried using @onselectionchange, but that does nothing(doesn't run the function). I could forget the @bind and just assign @onchange to a function, but I'm not sure how to pass the selected value to the function.

我有以下代码:

<select @bind="@SelectedCustID" @ @onchange="@CustChanged" class="form-control">
    @foreach (KeyGuidPair i in CustList)
    {
        <option value="@i.Value">@i.Text</option>
    }
</select>

谢谢.

推荐答案

<input @bind="MyProperty" />

@code  {
    private string myVar;

    public string MyProperty
    {
        get { return myVar; }
        set
        {
            myVar = value;
            SomeMethod();
        }
    }

    private void SomeMethod()
    {
        //Do something
    }
}

这篇关于Blazor:如何在&lt; select&gt;中使用onchange事件.还使用@bind时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆