Reputation: 31
I'm using ant design blazor (.net 5.0, antblazor 0.7.4) and try to trigger @onclick the Button render by 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>;
}
But get error: screen error
How to resolve this ? Tks a lots!
Upvotes: 2
Views: 1392
Reputation: 1964
@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>;
}
Upvotes: 1