我是 blazor C# 的新手,正在尝试制作一个简单的倒数计时器网站。我的网站包括:
我在设置计时器的按钮上遇到了问题。当我点击它时,它不会设置计时器显示并且我收到一个错误Argument 2: cannot convert from 'void' to 'Microsoft.AspNetCore.Components.EventCallback'。我在 Youtube 上搜索 EventCallback 主题,但问题是,我的组件没有分离,而在视频中,示例代码将分离的组件链接在一起。这是代码。
Index.razor
@page "/"
@inherits FrontEnd.Components.Timer
<h1>Timer</h1>
<p class="timer">@Hours.ToString("00"):@Minutes.ToString("00"):@Seconds.ToString("00")</p>
@foreach (var timer in timerCollections)
{
// Here's the problem
<button @onclick="SetTimer(timer.Id)">@timer.Hours.ToString("00"):@timer.Minutes.ToString("00"):@timer.Seconds.ToString("00")</button>
}
<br/>
<button @onclick="StartTimer" disabled=@StartButtonIsDisabled>Start</button>
<button @onclick="StopTimer" disabled=@StopButtonIsDisabled>Stop</button>
Run Code Online (Sandbox Code Playgroud)
定时器.cs
using System;
using System.Timers;
using System.Collections.Generic;
using Microsoft.AspNetCore.Components;
namespace FrontEnd.Components
{
public class TimerStructure
{
public int Id { get; set; }
public int Hours { get; set; }
public …Run Code Online (Sandbox Code Playgroud) 我现在正在尝试 Blazor 一段时间,我正在尝试找到关于两者之间差异的解释
<input type="button" onclick="@methodCall()">Something</button>
Run Code Online (Sandbox Code Playgroud)
和
<input type="button" @onclick="() => methodCall()">Something</button>
Run Code Online (Sandbox Code Playgroud)
为什么 @ 在 onclick 之前是预期的,而 @ 是价值的一部分?