如何在RenderFragment Antd Blazor中触发@onclick



我正在使用ant design blazor(.net 5.0,antblazor 0.7.4(,并尝试触发@onclick按钮渲染RenderFragment:App.razor

@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>;
}

相关内容

  • 没有找到相关文章

最新更新