[英]Ant Design Blazor Show message Callback not working
I am trying to get a message to show up using the a card with actions from Ant Design Blazor;我正在尝试使用带有 Ant 设计 Blazor 的操作的卡显示一条消息; however, for some reason I am getting an error that says "Keyword this is not available in the current context".但是,由于某种原因,我收到一条错误消息,提示“关键字在当前上下文中不可用”。
This is specifically due to the following RenderFragment:这特别是由于以下 RenderFragment:
private RenderFragment actionEdit =@<Template><Button Type="primary" Icon="edit" OnClick="ShowMessage" /></Template>;
The full code for the page is below.该页面的完整代码如下。 This was created using.Net 5 on Visual Studio 2019 using the Blazor Server这是使用 Blazor 服务器在 Visual Studio 2019 上使用 .Net 5 创建的
@page "/"
@inject MessageService _message
<PageContainer Title="Template">
<Card>
<Alert Message="Welcome to the Blazor - Ant Design Template"
Type="success"
ShowIcon
Banner
Style="margin: -12px; margin-bottom: 24px" />
<Text Strong>
<a target="_blank" rel="noopener noreferrer" href="https://https://antblazor.com/en-US/components">
Ant Design Blazor - Use this library for UI Components
</a>
</Text>
<Text Strong
Style="margin-bottom: 12px">
<a target="_blank" rel="noopener noreferrer" href="https://docs.microsoft.com/en-us/aspnet/core/blazor/?view=aspnetcore-5.0">
Blazor Introduction
</a>
</Text>
<Text Strong
Style="margin-bottom: 12px">
<a target="_blank" rel="noopener noreferrer" href="https://medium.com/swlh/using-npm-packages-with-blazor-2b0310279320">
NPM WebPack
</a>
</Text>
<Text Strong
Style="margin-bottom: 12px">
<a target="_blank" rel="noopener noreferrer" href="https://github.com/Azure-Samples/ms-identity-blazor-server/tree/main/WebApp-OIDC/MyOrg/blazorserver-singleOrg">
Authentication
</a>
</Text>
</Card>
<div>
<Card Style="width:300px;" Bordered Cover=@image Actions="new[] { actionSetting, actionEdit }">
<CardMeta Title="Meta Card" Description="Create Some Cards" />
</Card>
</div>
</PageContainer>
@code
{
private RenderFragment actionSetting =@<Template><Button Type="primary" Icon="setting" /></Template>;
private RenderFragment actionEdit =@<Template><Button Type="primary" Icon="edit" OnClick="ShowMessage" /></Template>;
private RenderFragment image = @<ImageCard source="/Images/58adc5e81f9a190b00c2fc4f_lo.png" />;
private void ShowMessage(MouseEventArgs e)
{
_message.Info("test");
}
}
Any thoughts on the way to resolve this or a resource to explain what is happening here?关于解决此问题的方法或解释这里发生的事情的资源的任何想法?
You are on the right track, but you missed one thing - you need to add a container component named <AntContainer />
to the App.razor
component.您在正确的轨道上,但您错过了一件事 - 您需要将一个名为<AntContainer />
的容器组件添加到App.razor
组件。
So, in order to display a message using the Message component, you need to make sure that the <AntContainer />
component has been added to App.Razor
.因此,为了使用 Message 组件显示消息,您需要确保已将<AntContainer />
组件添加到App.Razor
中。
Then use for example like this:然后像这样使用:
@inject MessageService _message
<Button Type="primary" Icon="edit" OnClick="ShowMessage" />
@code
{
private void ShowMessage(MouseEventArgs e)
{
_message.Info("test");
}
}
More details:更多细节:
AntBlazor Docs - Message Component AntBlazor 文档 - 消息组件
This issue on AntBlazor's Github page AntBlazor 的 Github 页面上的此问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.