Bind:在服务器端 blazor - c# - mudblazor 中未调用分配的方法之后

问题描述 投票:0回答:1

我尝试使用 @bind-Value 和 @bind-Value:after 在绑定发生后调用方法,但我的代码要么出现错误,要么不会调用该方法。

这样我得到错误编译器错误 CS0407 '返回类型方法'有错误的返回类型

<MudCheckBox Label="@R["Show title"]" Disabled="(!MayEdit && !MayDelete)" @bind-Value="@OptionsModel.Title_Visible" T="bool" @bind-Value:after="IsDirty"></MudCheckBox>

如果我在方法中添加括号,它会抱怨编译器错误 CS1503 参数“1”无法从“bool”转换为“System.Action”

如果我将它放入 lambda 中,它将编译,但当复选框更改时不会调用该方法

<MudCheckBox Label="@R["Show title"]" Disabled="(!MayEdit && !MayDelete)" @bind-Value="@OptionsModel.Title_Visible" T="bool" @bind-Value:after="(() => IsDirty())"></MudCheckBox>

方法在类文件ChartPropertyView.razor.cs中,Checkbox在ChartPropertyView.cs中

public override bool IsDirty()

IsDirty() 在 VS Professional 2022 V.17.7.7 中不会变成黄色,并且无法像平常一样悬停以获取信息

c# asp.net-core data-binding blazor mudblazor
1个回答
0
投票

你可以尝试这个代码,函数颜色变成黄色:

@page "/"
@rendermode InteractiveServer

<input @bind-value="aa" @bind-value:after="()=>{IsDirty();}"></input>

@code{
    private string aa="abc";
    public bool IsDirty(){
        Console.WriteLine("test");
        return false;
    }
}

© www.soinside.com 2019 - 2024. All rights reserved.