最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

asp.net core - MudSelect change event is not firing - Stack Overflow

programmeradmin6浏览0评论

Im unabe to fire a change event on a MudSelect component.

<MudSelect T="string" Label="US States" MultiSelection="true" @bind-SelectedValues="_selectedLevels" @bind-SelectedValues:event="OnLevelChange">

@foreach (var level in levels)
{
    <MudSelectItem T="string" Value="@level.Value">@level.Text</MudSelectItem>
}
private IEnumerable<string> _selectedLevels = new List<string> { "Error", "Warn" };
private async Task OnLevelChange(IEnumerable<string> selectedLevels)
{        
    await loggrid.ReloadServerData();
}

I also tried the @onchange event, but with no luck. I would appreciate any help.

Im unabe to fire a change event on a MudSelect component.

<MudSelect T="string" Label="US States" MultiSelection="true" @bind-SelectedValues="_selectedLevels" @bind-SelectedValues:event="OnLevelChange">

@foreach (var level in levels)
{
    <MudSelectItem T="string" Value="@level.Value">@level.Text</MudSelectItem>
}
private IEnumerable<string> _selectedLevels = new List<string> { "Error", "Warn" };
private async Task OnLevelChange(IEnumerable<string> selectedLevels)
{        
    await loggrid.ReloadServerData();
}

I also tried the @onchange event, but with no luck. I would appreciate any help.

Share Improve this question edited Mar 28 at 1:55 Qiang Fu 9,3871 gold badge6 silver badges16 bronze badges asked Mar 26 at 21:02 user49126user49126 1,8858 gold badges31 silver badges56 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

"@bind-xxx" means two-way binding. @bind-xxx:eventis used like @bind-xx:event="onchange" or @bind-xxx:event="oninput" to infer the binding is triggered when input or "textbox lose focus".
You should use @bind-SelectedValues:after instead

<MudSelect T="string" Label="US States" MultiSelection="true" @bind-SelectedValues="_selectedLevels" @bind-SelectedValues:after="()=>{OnLevelChange(_selectedLevels);}">

Or you could use MudBlazor built-in one-way bind to trigger the event and bind selectedValues manually.

<MudSelect T="string" Label="US States" MultiSelection="true"  SelectedValues="_selectedLevels" SelectedValuesChanged="OnLevelChange" >
...
    private async Task OnLevelChange(IEnumerable<string> selectedLevels)
    {
        _selectedLevels = selectedLevels;
    }
发布评论

评论列表(0)

  1. 暂无评论