[英]Blazor Child Component EventCallBack not responding
此处页面组件
@page "/student"
<h3>Student List</h3>
<h5>@StudentsList</h5>
<StudentDetail StudentName="Something New" ButtonClicked="@Save"></StudentDetail>
<h5>This is second</h5>
<h5>@SaveMessage</h5>
@code {
public string StudentsList { get; set; }
private string SaveMessage { get; set; }
protected override async Task OnInitializedAsync()
{
StudentsList = "ASD DSA KDS CFA";
}
private void Save(MouseEventArgs e)
{
SaveMessage = "Operation Saved.";
}
}
这是 StudentDetail
<h3>Student Detail for @StudentName</h3>
<button class="btn btn-primary" @onClick="ButtonClicked">Click Me!</button>
@code {
[Parameter]
public string StudentName { get; set; }
[Parameter]
public EventCallback<MouseEventArgs> ButtonClicked { get; set; }
}
我在服务器端和客户端都试过这个。 当我点击“点击我!” 按钮,绝对没有任何反应。 我究竟做错了什么?
这些是进口
@using System.Net.Http
@using System.Net.Http.Json
@using Microsoft.AspNetCore.Authorization
@using Microsoft.AspNetCore.Components.Authorization
@using Microsoft.AspNetCore.Components.Forms
@using Microsoft.AspNetCore.Components.Routing
@using Microsoft.AspNetCore.Components.Web
@using Microsoft.JSInterop
@using BlazorApp4
@using BlazorApp4.Shared
学生详情:
它的@onclick
,不@onClick
在@onClick="ButtonClicked"
当你点击"Click Me!"
按钮,您实际上想要触发 Student 组件中的“保存”方法。 这就是你这样做的方式:
`@onclick="() => ButtonClicked.InvokeAsync()"`
学生:将ButtonClicked="@Save"
更改为ButtonClicked="Save"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.