【发布时间】:2020-08-28 13:38:25
【问题描述】:
我刚开始阅读 Blazor 教程,并试图掌握代码。我有一个看起来像这样的剃须刀页面(来自教程):
@page "/counter"
<h1>Counter</h1>
<p>Current count: @currentCount</p>
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
<!--
This has been moved to the code-behind.
@code {
private int currentCount = 0;
private void IncrementCount() {
currentCount++;
}
}
-->
后面的代码给了我几个错误,说 Counter 已经定义并且 IncrementCount 已经存在。我的代码如下所示:
using Microsoft.AspNetCore.Components;
namespace BlazorApp8.Pages {
public partial class CounterCode : ComponentBase {
protected int currentCount = 0;
protected void IncrementCount () {
currentCount++;
}
}
}
我知道我做错了一些简单的事情,但不确定是什么。有人可以帮忙吗?
【问题讨论】:
-
为什么需要分部类?
-
我没有。那是我试图弄清楚我在做什么。我刚刚遗漏了一行代码(请参阅下面的答案)。
标签: blazor code-behind