簡體   English   中英

如何在 RenderFragment Antd Blazor 中觸發 @onclick

[英]How to trigger @onclick within RenderFragment Antd Blazor

我正在使用 ant 設計 blazor (.net 5.0, antblazor 0.7.4) 並嘗試通過 RenderFragment 觸發 @onclick 按鈕渲染:App.Z60C05C6Z32A28216E5478

   @inject NavigationManager NavigationManager

<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="@typeof(BasicLayout)" />
    </Found>
    <NotFound>
        <LayoutView Layout="@typeof(BasicLayout)">
            <Result Status="404"
                    Title="404"
                    SubTitle="Sorry, the page you visited does not exist."
                    Extra="extra" />
        </LayoutView>
    </NotFound>
</Router>
<AntContainer />
@code
{ 
    private void NavigateToHome()
    {
        NavigationManager.NavigateTo("/");
    }
    RenderFragment extra =@<Button Type="primary" @onclick="NavigateToHome">Back Home</Button>;

}

但得到錯誤:屏幕錯誤

如何解決這個問題? 非常感謝!

@inject NavigationManager NavigationManager

<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="@typeof(BasicLayout)" />
    </Found>
    <NotFound>
        <LayoutView Layout="@typeof(BasicLayout)">
            <Result Status="404"
                    Title="404"
                    SubTitle="Sorry, the page you visited does not exist."
                    Extra="HomeButton(NavigateToHome)" />
        </LayoutView>
    </NotFound>
</Router>
<AntContainer />
@code
{ 
    private void NavigateToHome()
    {
        NavigationManager.NavigateTo("/");
    }
    RenderFragment HomeButton(Action clickAction) => @<Button Type="primary" @onclick="@clickAction">Back Home</Button>;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM